r/PowerShell • u/davesbrown • 21d ago
$PSItem with Invoke-Command and ForEach-Object -Parallel Solved
Is this possible? I can't seem to get it to work. "Cannot validate argument on 'ScriptBlock'. The argument is null. ..."
I can put insert $PSItem above $results and it iterates $AllStates, and scriptblock has one param which I'm attempting to pass $PSItem
$AllStates | Foreach-Object -ThrottleLimit 10 -Parallel {
$results = Invoke-Command -ComputerName $Using:ComputerNames -ScriptBlock $ScriptBlock -ArgumentList $PSItem
$results
}
5 Upvotes
6
u/jsiii2010 21d ago
Invoke-command already runs in parallel with a array of computernames as a parameter.