Sunday, March 21, 2010

Easily run commands on many machines with powershell

Need to run a series of commands on a bunch of machines in a row? Try something like this in PowerShell:

01,02,03,04,05,08,09,10,19,20,21 |
%{"base10name12{0:D2}" -f $_} | %{
Enable-WSManCredSSP client $_
invoke-command -comp $_ { cp D:\logs\* \\server\share\logs }
restart-computer $_
}

No comments: