Forum Discussion
Pradeep MISHRA
Aug 09, 2020Copper Contributor
Unable to script using Multi-threading
I have one Csv and there are 10 VM and i want to run this script to all the vms in same time (using Multi-threading concept or any other method) not one by one. because if it will run one by one ...
Rolf-42
Aug 11, 2020Iron Contributor
Hello Pradeep MISHRA
If you are able to use PowerShell 7 you may want to consider the new parallel option for the foreach-object Cmdlet.
I hope that helps
Cheers
Rolf
#MCT #LearnWithRolf #TheCloud42
- Pradeep MISHRAAug 15, 2020Copper Contributor
Rolf-42 ,
I am using below powershell version and unable to using workflow
PS C:\Users\Admin> Get-Host | Select-Object Version
Version
-------
5.1.19041.1Can you please share a sample ?
- Rolf-42Aug 16, 2020Iron Contributor
Hello Pradeep MISHRA
Since your PowerShell version is to low what about running PowerShell 7 in a container? https://www.thomasmaurer.ch/2020/03/run-azure-powershell-in-a-docker-container/
If that is not possible the background job feature is your approach https://docs.microsoft.com/en-us/powershell/scripting/developer/cmdlet/background-jobs?view=powershell-5.1
Start-Job -ScriptBlock { Get-Process -Name powershell } is the example you are looking for.
The example is taken from the Start-Job documentation here: https://docs.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Core/Start-Job?view=powershell-5.1#examples
Cheers
Rolf
#MCT #LearnWithRolf #TheCloud42