Update: Creating a profile for a remote session


So not too long ago I found a way to create a remote profile but there was one problem with it, it was a little sloppy in that it wouldn’t close the sessions. I haven’t found a way for it to close the sessions yet, and I’m not sure I want to. What I have done is get it to manage it’s sessions a little better. Here is the updated script.

function connect ($hname){
    #clean out non-open connections
    gsn | Where-Object {$_.state -ne "Opened"} | rsn
    #Check for Open Sessions

    if($session = gsn | Where-Object {$_.computername -eq $hname})
    {
        Write-Host "Reusing Connection!"
    }
    else
    {   
        Write-Host "Creating New Connection!"
        $session = new-pssession $hname
        icm -session $session -scriptblock{
       
####START REMOTE PROFILE####

            function prompt
            {
                Write-Host $(Get-Date -Format [HH:mm:ss])  -NoNewline -ForegroundColor Blue
                write-host $(get-location) -nonewline -foregroundcolor white
                return ">"
            }
        ####END REMOTE PROFILE####
        }
    }
    enter-pssession $session
}

As you can see there is a section marked Remote profile. I have only created a remote prompt but you can get it to do other things, for example load Quest modules or whatever it is you have in your normal profile.

Advertisements

About jrich

I am the Solutions Architect for Apex Learning in Seattle WA. I've been working with computers since I was 13. Started programming when I was 14. Had my first IT job as tech support at an ISP at the age of 15 and became a network admin at the age of 17. Since then I've worked at a variety of small to mid size companies supporting, maintaining and developing all aspects of IT. Mostly working with Windows based networks but have recently been working with Solaris system as well. I created this blog mostly as a place for me to take my own notes, but also share things that I had a hard time finding the info for.

Posted on July 21, 2010, in WMF (Powershell/WinRM) and tagged , . Bookmark the permalink. 2 Comments.

  1. you can use “set-pssessionconfiguration -name MaintenanceShell -startupScript c:\ps-test\Maintenance.ps1” in the target computer, where Maintenance.ps1 contains all your functions,
    and from the local computer
    “enter-pssession -computername yourtarget -configurationname maintenanceshell -credential youradminuser@yourtargetdomain

    cheers!

  2. Adrian T. :
    you can use “register-pssessionconfiguration -name MaintenanceShell -startupScript c:\ps-test\Maintenance.ps1″ in the target computer, where Maintenance.ps1 contains all your functions,
    and from the local computer
    “enter-pssession -computername yourtarget -configurationname maintenanceshell -credential youradminuser@yourtargetdomain
    cheers!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: