GUI Script Getting Stuck on SCVMM Cmdlet

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
Posts: 1
Joined: Thu Oct 12, 2017 12:16 pm

GUI Script Getting Stuck on SCVMM Cmdlet

Post by pdavapark » Wed Aug 28, 2019 6:42 am

I found another topic on this exact same issue that never seems to have received any sort of resolution. Link to related thread at the bottom.

What seems to happen is the script seemingly just "stops" when executing certain cmdlets in the VMM module for System Center. Example cmdlet I'm having issues with right now is New-SCHardwareProfile. Running it in ISE or a regular Powershell console works perfectly fine, running the exact same thing through my GUI app in PS Studio completes the task it's supposed, you see the new hardware profile created in VMM, but the script just completely stops there with zero output to the console during debugging or anything. No errors, no output at all, it just hangs like it's waiting for some response or something that it never seems to get.

I've tried kicking it off as a job, running the command in another script, piping to random other cmdlets with an error action of SilentlyContinue to hopefully just break the pipe and let it continue, all to no avail. I've also tried using the -RunAsynchronously switch, still no luck. Running it as a job or in a separate script results in an error from VMM about losing its connection to the VMM server, error 1610. I believe this has something to do with it making a new "connection" to VMM but I'm not 100% sure.

Any thoughts on how to force the script to just continue on without waiting for a response from cmdlet? Anything I can find involves a timer and running it as a job but running it as a job just doesn't seem to work, something with the connection to VMM not being happy.

OS is Server 2016 x64.

Related thread:

Posts: 14135
Joined: Tue May 22, 2007 9:57 am

Re: GUI Script Getting Stuck on SCVMM Cmdlet

Post by jvierra » Wed Aug 28, 2019 6:59 am

This is a common issue when using a form for some modules that perform remoting. The issue is because the main thread of PowerShell receives the results but that thread is blocked by the form.

The only reliable method I have found is to run your SCVVM scripts in a job and return the results to the GUI. The session in the job cannot be accessed from the form.