PowerShell: Enable Remoting

I faced the task to create some scripts which perform a backup on our Microsoft Windows Server 2008 systems used for user acceptance testing. Before each deployment, a backup of the currently deployed database and applications should happen. Our database is based on Microsoft SQL Server 2008 and our applications are built on Microsoft ASP.NET and Microsoft Internet Information Services 7. Since we have several servers for testing, I wanted to create a solution, which allows me to upload scripts to the remote system and then execute them afterwards. This seemed to be the perfect case for Microsoft Windows PowerShell, since the Remoting feature allows me to do exactly that – upload a script and execute it.

PowerShell Remoting allows you to communicate with remote systems and execute PowerShell scripts on them. You can even run the same script on several systems at the same time.

To setup PowerShell Remoting, you have to conduct the following steps:

  1. On the server: Enable remoting:
    PS C:\> Enable-PSRemoting
  2. On the client: Switch to the WSMAN section:
    PS C:\> cd wsman:\localhost\Client
  3. On the client: Add the server to the list of trusted hosts:
    PS WSMan:\localhost\Client> Set-Item TrustedHosts -Value * -force
  4. On the client: Allow data to be transferred unencrypted between client and server:
    PS WSMan:\localhost\Client> Set-Item AllowUnencrypted -Value $true -force

For increased security you can of course force https to be used as transport protocol. Moreover, you can limit the trusted hosts to the IP/hostname you really need (* means every host is allowed to connect).

[1] http://social.technet.microsoft.com/wiki/contents/articles/2504.enable-powershell-remoting-with-client-outside-of-server-s-domain-trusted-host-and-double-hop-issue.aspx

[2] msdn.microsoft.com/en-us/library/windows/desktop/aa384426(v=vs.85).aspx

Leave a Reply

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