Running Commands On Multiple Computers

You can work remotely not just for single computers. You can also run your commands against multiple computers like this:

$computer = Get-Content computers.txt
$session = New-PSSession -ComputerName $computer
Invoke-Command -Session $session { md hklm:\software\hey }

Here, you can see how remote commands reuse an existing session that was created previously with New-PSSession. You can specify one or more computer names when you establish the session. In the example, all computer names are read from a plain text file.

The command in brackets is simultaneously executed on all computers the session was set up for whenever you use Invoke-Command against the existing session. In the example, a new registry key is created. PowerShell limits the number of simultaneous connections to 32 (unless you change this with the -throttleLimit parameter) so if you should specify more than 32 computers, it will postpone additional calls.

Twitter This Tip! ReTweet this Tip!


Posted Nov 24 2009, 08:00 AM by ps1

Comments

Twitter Trackbacks for Running Commands On Multiple Computers - Power Tips - PowerShell.com [powershell.com] on Topsy.com wrote Twitter Trackbacks for Running Commands On Multiple Computers - Power Tips - PowerShell.com [powershell.com] on Topsy.com
on 11-24-2009 10:42 AM

Pingback from  Twitter Trackbacks for                 Running Commands On Multiple Computers - Power Tips - PowerShell.com         [powershell.com]        on Topsy.com

Running Commands On Multiple Computers - Power Tips - PowerShell.com « Internet Cafe Solution wrote Running Commands On Multiple Computers - Power Tips - PowerShell.com « Internet Cafe Solution
on 11-24-2009 6:25 PM

Pingback from  Running Commands On Multiple Computers - Power Tips - PowerShell.com «  Internet Cafe Solution

Running Commands On Multiple Computers - Power Tips - PowerShell.com wrote Running Commands On Multiple Computers - Power Tips - PowerShell.com
on 11-24-2009 9:36 PM

Pingback from  Running Commands On Multiple Computers - Power Tips - PowerShell.com

Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.