PowerShell version 7 has option to run tasks in Parallel.
This would mean that task that can be run in Parallel mode and tasks can be done simultaneously and save time.
How to get started or making use of Parallel in PowerShell?
First, PowerShell has to be in version 7.
Version 7 of PowerShell can be downloaded from Microsoft via this link below.
Choose the version, whether its x86 or x64.
The CPU architecture in your system will determine whether x64 PowerShell can be used or not.
Sample code below, shows how Parallel processing in PowerShell can be done.
$HostsIPs = '127.0.0.1','8.8.8.8','8.8.4.4','1.1.1.1'
$HostsIPs | ForEach-Object -Parallel {
Test-Connection $_
} -ThrottleLimit 5
The screenshot image below, shows that the commands indeed were processed in a Parallel mode since it was executed simultaneously.
The number on the left side shows number "3", or "4".
In which it shows that all the commands were executed at the same time.
This code below shows how to execute same function as above but not using Parallel Processing.
$HostsIPs = '127.0.0.1','8.8.8.8','8.8.4.4','1.1.1.1'
$HostsIPs | ForEach-Object {
Test-Connection $_
}
The screenshot image below which does not utilize the Parallel processing, shows that the commands were executed one after the other.
The number on the left side shows that the commands were executed in an orderly fashion, as it shows "1", "2", "3" and "4".
So, PowerShell Parallel processing is quite awesome.
But yes, not all tasks can be run in Parallel mode, especially if the task needs to wait the output of the previous command before it can run or execute.
However, if commands can utilize Parallel processing then I guess that would be the best option since it will save a lot of time at the expense of the processing resources in your system.
Comments
Post a Comment