So, I'm using invoke-command to run a script against more than one server simultaneously:
Invoke-Command -ComputerName $Servers -Credential $Cred -FilePath "C:\RemoteScript.ps1"
However the results appear to be out of order:
User: username FQDN: DEVSERVER01.localnet.int IP: 10.0.0.101
Server uptime: 20 days
======================
User: username
FQDN: DEVSERVER02.localnet.int
IP: 10.0.0.202
Server uptime: 20 days
======================
User: username
FQDN: DEVSERVER03.localnet.int
IP: 10.0.0.303
Server uptime: 20 days
======================
List of updates for DEVSERVER01.localnet.int:
No updates
List of updates for DEVSERVER02.localnet.int:
No updates
List of updates for DEVSERVER03.localnet.int:
No updates
I also want to log the results for each server but this is what I came up with:
Start-Process -FilePath Powershell -ArgumentList "
Invoke-Command -ComputerName $Server -Credential $Cred -FilePath "C:\RemoteScript.ps1"
" -RedirectStandardOutput "$Server Log.txt" -Wait
How should I be able to run my script on two servers but should try to get the results from each server in order?