It’s a pretty routine event for me to be remotely logged into more then one Windows server through Remote Desktop, or even occasionally sending a command from CMD to a remote server. PowerShell has not been left out of the game, when it comes to remote computing. If you have a Windows 7, and a Windows 2008 machine, then everything you need has likely already been installed. In this blog I will discuss the steps needed to make and accept connections from PowerShell, and discuss running a single command on a remote computer. If not then you will need to download and install the Windows Management Framework Core package. You can find it here: support.microsoft.com/kb/968930
4 things must be in place before a computer will accept remote PowerShell connections.
- The WinRM service must be running.
- There must be a WinRM listener that accepts connections from one or more IP addresses.
- The Windows firewall must be configured to allow the WinRM connection.
- There must be an enabled and properly configured PowerShell session.
Now if the computer isn’t going to be accepting remote PowerShell connections, then you don’t need to worry about the above list.
Assuming that you will be accepting remote PowerShell connections, the First thing you will need to do is open PowerShell with administrative privileges. This can be done by right clicking the PowerShell icon and selecting “Run as Administrator”. Now execute the cmdlet Enable-PSRemoting . If you would like to read more about the cmdlet type Get-Help Enable-PSRemoting.
Now, the easiest way to connect to PowerShell on a remote computer is to use the Enter-PSSession cmdlet. As with all cmdlets if you need help type Get-Help CMDletName.
PS C:> Enter-PSSession servername
The above CMDlet is an example of what you would type to establish a connection to a remote server. Once you are connected to that server the PowerShell prompt changes to [servername]: PS C:>
Once you’re connected remotely, any commands you enter at the prompt are executed on the remote computer. For example you can list the files and folders on the remote computer by typing [servername]: PS C:> Get-ChildItem C:
To end your session, type [servername] PS C:> Exit-PSSession
Next time I’ll continue this by showing you how to run a Scriptblock on a remote computer!
Leave a Reply
You must be logged in to post a comment.