Powershell Remoting

 

Running scripts on remote computers can be done in several different ways.

First the WinRM service needs to be started on the remote computers in order to manage them. In Windows 2012 WinRM is turned on by default. In a domain you can enable this for the rest of the computers via group policies:
computer configurationpoliciesadministrative templateswindows componentswindows remote ManagementWinRM Service
or on the computer itself:

Within Powershell there are two methods of remoting. 1-to-1 and 1-to-many. 1-to-1 gives you a command-line prompt on a remote computer. The socond, 1-to-many gives you the possiblity to send a command (or more then one) parallel to a bunch of computers.

Make a 1 to 1 connection to a computer:

It is important to know that a enter-pssession sends the commands from your keyboard to the remote computer and sends the result back to your screen. This is an interactive session and therefore it will not run in a script. The code will be executed on the local computer instead of the remote.

Make a 1 to many connection.

Do stuff on a bunch of computers via the Invoke-Command:

Or for short you can use the following witch does the same:

Sessions

Invoke-command and enter-pssession creates a session to a remote computer, executes a command and closes the session. This can create some overhead if you need to run multiple commands to remote computers. Sinds the remote session is disconnected once done, all variables set in previous commands are not kept for the next commands.

As you can see the content of the variable is lost in this example

You can use a persistant session witch are much faster and, sinds the are left open, variables are kept and reusable.

Powershell Web Access

An other way to manage computers remotely is to use Powershell via a Web browser from any device. First you need to install a Windows feature ‘Windows PowerShell Web Access’ for on a Windows 2012 or higher computer.

This will install the windows feature. To get help on the commandlets use:

To get the website up and running:

Now you can browse to the website you just have created.

Leave a Reply

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