Solved

adding a powershell snappin asynchronously

Posted on 2013-12-16
5
466 Views
Last Modified: 2014-01-06
I am writing a powershell based application using winforms which is intended to deploy servers using SCCM. One of the functions the application provides is the creation of virtual machines using the VMware PowerCLI pssnapin. The problem is that the when the app is run, the add-pssnapin takes around 50 secs to complete, during which time it looks like the app has hung.
I've tried using start-job to add the snapin, but it doesn't seem to work - any calls to the powercli cmdlets fail.
0
Comment
Question by:aferr
  • 3
  • 2
5 Comments
 
LVL 68

Expert Comment

by:Qlemo
ID: 39721701
Would really surprise me if anyone came up with something. You need the imported cmdlets, so how should that work? Remember - the snap-in changes your PS environment ...
0
 

Author Comment

by:aferr
ID: 39723550
I'm aware of the fact that the snapin changes the environment, what I'm trying to do is find a way to load it without having the application/script take a massive pause as it loads.
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 39723779
Didn't try, but maybe it works if you create a new session with start-job, importing the PowerCLI snap-in, and then Import-PsSession as soon as the job is ready again. Importing a session should work much faster than importing a module (the first time).

Another way is to start the whole application with a correct PowerCLI session configuration. You will have the delay when starting the application, though.
0
 

Author Comment

by:aferr
ID: 39734746
Tried your suggestion but ironically it took longer to import the session than it did to add the snappin
0
 
LVL 68

Accepted Solution

by:
Qlemo earned 500 total points
ID: 39734771
Sad. I was afraid of that. Importing a session involves creating proxy calls, which puts more workload on it overall.
Are you able to use the session configuration from start, as PowerCLI does? What I refer to is something along:
powershell.exe -psc "C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" -noe -c ". \"C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1\""

Open in new window

0

Featured Post

Shouldn't all users have the same email signature?

You wouldn't let your users design their own business cards, would you? So, why do you let them design their own email signatures? Think of the damage they could be doing to your brand reputation! Choose the easy way to manage set up and add email signatures for all users.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
login with Vsphere Client 14 45
Extraction Tool 2 37
firefox deployment by sccm 1 20
Powershell - Compare two variables 1 10
Exchange server is not supported in any cloud-hosted platform (other than Azure with Azure Premium Storage).
Will try to explain how to use the VMware feature TAGs in the VMs and create Veeam Backup Jobs using TAGs. Since this article is too long, I will create second article for the Veeam tasks.
Teach the user how to edit .vmx files to add advanced configuration options Open vSphere Web Client: Edit Settings for a VM: Choose VM Options -> Advanced: Add Configuration Parameters:
This Micro Tutorial steps you through the configuration steps to configure your ESXi host Management Network settings and test the management network, ensure the host is recognized by the DNS Server, configure a new password, and the troubleshooting…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now