Solved

adding a powershell snappin asynchronously

Posted on 2013-12-16
5
479 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 69

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 69

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 69

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An article on effective troubleshooting
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
This video shows you how to use a vSphere client to connect to your ESX host as the root user. Demonstrates the basic connection of bypassing certification set up. Demonstrates how to access the traditional view to begin managing your virtual mac…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

749 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