Don’t do that #22: Manage a remote server using RDP

By | April 22, 2015

Don’t do that: You need to manage a server and you connect to the server via RDP, you open Powershell and you start typing cmdlets.


Do that: I don’t like this approach because it’s a waste of time (wait for logon and logoff) and it uses more resources on the remote computer.

If PSRemoting is enabled, you can start a session on the remote computer (you write commands on your local computer and these are sent to the remote computer for execution, results are serialized into XML and transmitted back to your local computer which will deserialize them into objects).

PowerShell remoting is enabled by default on Windows Server 2012 and later server operating systems.
It is not enabled by default on client operating systems (including Windows 8 and 8.1).

In a domain, you can also create a GPO to enable remoting (in case you need to enable on a large number of computers).

To manually enable PSRemoting on a local computer (as an administrator):

test-wsman

Enable-PSRemoting is a persistent change (although it can be disabled with Disable-PSRemoting) and does the following:

  • Create an exception in the Windows Firewall for incoming TCP traffic (port 5985)
  • Create an HTTP listener on port 5985 for all local IP addresses
  • Set the WinRM service to start automatically and restart it
  • Register up to four default endpoints for use by PowerShell

To enable PSRemoting on a remote computer:

PsExec can be downloaded here.

Note: if you just want to send a specific command (contained in the script block) to a remote computer:
Invoke-Command -ComputerName server -ScriptBlock { $env:COMPUTERNAME } -Credential $credentials


previous-buttonNext button blue

Leave a Reply

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