Solved

adding a powershell snappin asynchronously

Posted on 2013-12-16
5
470 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

HOW TO: Install and Configure VMware vSphere Hypervisor 6.5 (ESXi 6.5), Step by Step Tutorial with screenshots. From Download, Checking Media, to Completed Installation.
When rebooting a vCenters 6.0 and try to connect using vSphere Client we get this issue "Invalid URL: The hostname could not parsed." When we get this error we need to do some changes in the vCenter advanced settings to fix the issue.
Teach the user how to join ESXi hosts to Active Directory domains Open vSphere Client: Join ESXi host to AD domain: Verify ESXi computer account in AD: Configure permissions for domain user in ESXi: Test domain user login to ESXi host:
This Micro Tutorial walks you through using a remote console to access a server and install ESXi 5.1. This example is showing remote access and installation using a Dell server. The hypervisor is the very first component of your virtual infrastructu…

863 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

28 Experts available now in Live!

Get 1:1 Help Now