Hi,
You're confusing the ForEach-Object cmdlet with the ForEach keyword. It should be ForEach ($VDI in $AllVDI)
or $AllVDI | ForEach-Object -parallel
. The ForEach-Object -parallel is introduced in Powershell 7 yet the ForEach keyword doesn't support -parallel.
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/foreach-object?view=powershell-7.1
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_foreach?view=powershell-7.1
Another way to run the script in parallel is using jobs
https://devblogs.microsoft.com/scripting/parallel-processing-with-jobs-in-powershell/
Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.