Provided you have enabled PowerShell remoting (see our previous tips), you can easily run commands and scripts on many computers at the same time.
The example below illustrates this, and places a text file on the desktop of all users on the listed computers. Warning: this is a very powerful script. It executes anything you place in $code on all listed machines, provided remoting is enabled, and you have proper permissions:
# list of computers to connect to $listOfComputers = 'PC10','TRAIN1','TRAIN2','AD001' # exclude your own computer $listOfComputers = $listOfComputers -ne $env:COMPUTERNAME # code to execute remotely $code = { "Hello" | Out-File -FilePath "c:usersPublicDesktopresult.txt" } # invoke code on all machines Invoke-Command -ScriptBlock $code -ComputerName $listOfComputers -Throttle 1000
If you replace the code in $code with “Stop-Computer –Force”, for example, all machines would shut down.