VMware Cloud Community
sfresher
Contributor
Contributor

Run multiple PowerCLI scripts at the same time?

I am trying to use PowerCLI to automate a moderate amount (10 concurrent) of VM activities (start vm, shutdown vm, create snapshot, revert snapshot, etc).  What I did is I have create a powershell script (e.g. startvm.ps1, stopvm.ps1) for each of these activites, and I will call these scripts from my java service.

However, the problem is when calling scripts concurrently (about 10), it takes lots of system resources.  I even got this response from windows "Not enought quota to process this command." that prohibit the powershell script to execute.  Furthermore, it's also very slow to execute the each powershell script, because calling it each time is like a open a new session that it has to VI-Connnect to all the hosts at first. 

Am I doing the right way?  I really doubt it.

0 Kudos
3 Replies
LucD
Leadership
Leadership

A better way, imho, would be to have one PS script started, that keeps on running in a kind of endless loop, and that accepts 'directions' from your master program (which you wrote in Java).

For this you can use the Eventing mechanism that PowerShell v2 supports.

But you can also make your own kind of eventing system.

For example, when a specific action needs to be done, you create a file in a folder.

The background script keeps on monitoring that folder and when it sees a file appearing it will execute a specific task.

The parameters for that task could be stored inside the file.

In the background script you can have all the seperate scripts, you now use, as functions.


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

sfresher
Contributor
Contributor

Thank you, Luc.

I am very new to Power Shell.  For my power script that listens to event, I have to make it multithread, so that it can handling concurrent "directions" at the same time, right?  It sounds not a trival task.  Can you point me to some event mechnism that I can study on?

0 Kudos
LucD
Leadership
Leadership

I think the Start-Job cmdlet is the closest you can get to starting threads in PowerShell.


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

0 Kudos