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.
Technology Tips and News
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.
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:\ }
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.
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
Oh yes~~~ i Got it . thank you very much.
ps: another simple question
How Can I put the results to a TXT file?