• PowerShell Remoting

    by  • 2011/01/05 • Tech • 0 Comments

    I have been playing with Remoting in PowerShell a lot recently.  I don’t have it all figured out, but I’m getting there.

    Here are some of my notes.  (Run on Remote/Destination server, unless otherwise specified.)

    To have a custom profile when connected to another machine use:
    Register-PSSessionConfiguration -Name <name>   -StartupScript <scriptname>
    For consistency I use the local machine profile for my startup script (C:\Users\%username%\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1).

    To use the PSSessionConfiguration when connecting from your local machine using Enter- or New-PSSession include -ConfigurationName:
    New-PSSession <ServerFQDN>   -UseSSL -Credential <DomainUser>   -ConfigurationName <name>
    Using the name assigned when the PSSessionConfiguration was registered.

    To enable Remote PowerShell connections run:
    Set-WSManQuickConfig -UseSSL
    This will starts the service, sets it to automatic and add an exception to the Windows Firewall.

    The -UseSSL requires the computer to have a certificate installed that can be used for Server Authentication and it can’t be self-signed.  If you don’t have a CA in your domain don’t use this option.

    To connect to a machine in a different domain you must use SSL.

    In my profile on my local machine I have setup a function called New-PSSecureRemoteSession (with an alias of SSH) that sets up a new PSSession and then enters it.
    function New-PSSecureRemoteSession<br />
    {<br />
    param ($sshServerName, $Cred)<br />
    $Session = New-PSSession $sshServerName -UseSSL -Credential $Cred -ConfigurationName <name><br />
    Enter-PSSession -Session $Session<br />
    }

    About

    Clint McGuire is a Computer Consultant based out of Vancouver Canada. He specializes in VMware and Storage.

    Leave a Reply

    Your email address will not be published. Required fields are marked *