I am trying to run series of commands on remote Windows Servers.
Some of these servers are up and some of them not. To some I have access and to some of them I do not have access.
Options to address this:
I can go with:
$Computername = PC1, PC2, PC3
Invoke-Command -ComputerName $computerName -FilePath .\script
Now what bugs me is that the invoke-command timeout takes too long and cannot made shorter.
So what I was thinking about is to use PowerShell 7 Parallel loops + Invoke-Command + Powershell Jobs:
$server_list = Import-Csv .\server-list.csv
$list = $server_list.Name
$my_array = $list | Foreach-Object -ThrottleLimit 32 -Parallel {
$x = start-job -name $_ -ScriptBlock { invoke-command -ComputerName $_ -FilePath .\script.ps1}
$x | Wait-Job -Timeout 5
$x | Where-Object {$_.State -ne "Completed"} | Stop-Job
$zz = Receive-Job -Name $_
$zz
}
$my_array
Error I am getting is:
Invoke-Command: Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
Invoke-Command: Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
Invoke-Command: Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
Any idea how to address this?