How Can I run a script to all servers in my servers list

Hi Guys

I have a Servers list:servers.txt , it's including all servers i need to run a powershell script,how can I use the powershell to run a script on those servers? thank you.I just start to learn about powershell.

March 22nd, 2015 12:14am

If you have PowerShell Remoting enabled on your servers, you can just use Invoke-Command.  For example:

$servers = Get-Content servers.txt

Invoke-Command -ComputerName $servers -ScriptBlock { dir c:\ }

Free Windows Admin Tool Kit Click here and download it now
March 22nd, 2015 12:38am

for example the script name:copy.ps1 location:c:\ ,  the server list name:servers.txt

the command sould be:

$servers = Get-Content servers.txt

invoke-command -ComputerName $servers -ScriptBlock {c:\copy.ps1} 

right?

thank you.

March 22nd, 2015 12:51am

If copy.ps1 exists on every remote server, that would work.  If it's a script on your local computer, you'd use the -FilePath parameter instead of -ScriptBlock:

Invoke-Command -ComputerName $servers -FilePath c:\copy.ps1

Free Windows Admin Tool Kit Click here and download it now
March 22nd, 2015 1:03am

Oh yes~~~ i Got it . thank you very much.

ps: another simple question

How Can I put the results to a TXT file?

March 22nd, 2015 1:20am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics