PowerShell Remoting into Windows Server 2012

So my new love is PowerShell and as I like to spend my time (or whenver I get the chance) in CLI mode, anything is welcome!

Anyway, let’s get down to business. So Windows Server 2012 has been installed in my Virtualbox environment and I opted for the CLI mode (non-GUI) right from the start. Hey, if Microsoft are offering two install modes – CLI or GUI then I am assuming that you can do everything in both modes right?

And as PowerShell is native on Windows 7 and Windows Server 2012 why not remote in through PowerShell from your client workstation? Similar to SSH into your newly built *nix server eh? 😉

0. Open PowerShell by running powershell in the CMD window or by starting it from the Start Menu shortcut

1. Make sure that WinRM service is running – which it should be by default on Server 2012

PS C:\Users\Administrator\Documents> Get-Service WinRM

Status   Name               DisplayName
------   ----               -----------
Running  WinRM              Windows Remote Management (WS-Manag...

2. Next we’ll enable remoting

PS C:\Users\Administrator\Documents> Enable-PSRemoting -force
WinRM is already set up to receive requests on this computer.
WinRM has been updated for remote management.
Configured LocalACcountTokenFilterPolicy to grant administrative rights remotely to local users

3. And then on your client workstation fire up PowerShell and for starters we’ll add “Everything” to our TrustedHosts file so that we can connect to wherever we want:

PS C:\Users\ePlus> Set-Item WSMan:\localhost\Client\TrustedHosts -Value "*" -Force

4. Then we’ll start a PSSession, but I know we could have done Enter-PSSession instead of New-PSSession:

PS C:\Users\ePlus> New-PSSession -ComputerName -Credential administrator

 Id Name            ComputerName    State         ConfigurationName     Availability
 -- ----            ------------    -----         -----------------     ------------
  7 Session7   Opened        Microsoft.PowerShell     Available

5. And finally we’ll connect to the newly created PSSession and we’ll get the destination IP address as confirmation when we have successfully connected:

PS C:\Users\ePlus> Enter-PSSession 7
[]: PS C:\Users\Administrator\Documents>

3 Comments to “PowerShell Remoting into Windows Server 2012”

  1. in Windows 10, the syntax for setting TrustedHosts seems to have changed.

    Set-Item : The client cannot connect to the destination specified in the request. Verify that the service on the
    destination is running and is accepting requests. Consult the logs and documentation for the WS-Management service
    running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following
    command on the destination to analyze and configure the WinRM service: “winrm quickconfig”.
    At line:1 char:1
    + Set-Item WSMan:\localhost\Client\TrustedHosts -Value “*” -Force
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Set-Item], InvalidOperationException
    + FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.PowerShell.Commands.SetItemCommand

    1. > in Windows 10, the syntax for setting TrustedHosts seems to have changed.

      The following workaround works for me. On the client machine elevated powershell:
      1. Run the command WinRM QuickConfig. Then press Y at every confirmation.

      2. Re-run the command Set-Item WSMan:\localhost\Client\TrustedHosts -Value “*” -Force

      3. Finally, run the command New-PSSession -ComputerName bla.bla.bla -Credential Administrator. You should be able to get in.


Leave a Comment

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