VMware Cloud Community
Developer_PK
Enthusiast
Enthusiast
Jump to solution

parallel Execution using Powershell

I am working on a activity which needs to get uptime from several servers. I am using Invoke-vmscript to do this activity. I want to use Parallel processing to reduce time.

Without a new ps session and using jobs. Is there any other way to do parallel execution.

I have tried Foreach-object -parallel, this didnot work because my powershell version is not 7.

Any suggestion Helps!

Thanks in advance

Reply
0 Kudos
1 Solution

Accepted Solutions
8 Replies
LucD
Leadership
Leadership
Jump to solution

If your PS is not PSv7 and you don't want to use Start-Job, then the other option is to look at runspaces.
But be aware that PowerCLI is not threadsafe.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Developer_PK
Enthusiast
Enthusiast
Jump to solution

HI LucD,

Can you help me, by using jobs.
I had to run a script which is large on multiple servers. Can you help me with using Jobs.

Thanks in advance

 

Tags (1)
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Reply
0 Kudos
Developer_PK
Enthusiast
Enthusiast
Jump to solution

Hi LucD,
I got this warning in the job output. Can you help me with this.

WARNING: Please consider joining the VMware Customer Experience Improvement Program, so you can help us make PowerCLI a better product. You can join using the following c
ommand:

Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $true

VMware's Customer Experience Improvement Program ("CEIP") provides VMware with information that enables VMware to improve its products and services, to fix problems, and
to advise you on how best to deploy and use our products. As part of the CEIP, VMware collects technical information about your organization’s use of VMware products a
nd services on a regular basis in association with your organization’s VMware license key(s). This information does not personally identify any individual.

For more details: type "help about_ceip" to see the related help article.

To disable this warning and set your preference use the following command and restart PowerShell:
Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $true or $false.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That is a normal warning, just execute the command on the last line with either $true or $false.
You are setting up a new environment, hence this warning.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Developer_PK
Enthusiast
Enthusiast
Jump to solution

Thanks much for reply.
I want to send a Another variable to Argument list. So that it should Take the variable data in to code block.
Like I want to pass multiple variables to arugementlist. 
Is this possible?
I want to run a code block for multiple servers to fetch data.
$vmnames |%{
$scriptblock = { #code}
Start-Job $ScriptBlock -ArgumentList $_
}
This way i am using the code block. 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

If you read that thread I pointed to earlier, you'll notice it also discusses passing an array.
Also, in that thread I point to an example on my blog where we pass 3 arguments to the job.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Godwin_Christop
Enthusiast
Enthusiast
Jump to solution

you basically have the answer, just install the PowerShell 7 and get the job done,

and you don't have to worried about the warning,  just run the below command and be done with it.
Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP:$false 

✌️

Reply
0 Kudos