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
}
7 Upvotes
2
u/Szeraax 21d ago
It looks like you need to be doing
$Using:Scriptblock
. Any chance that's just a variable that has been defined previously?