SCVVM Command freezing in Forms

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
ITZBund_Ilmenau
Posts: 13
Joined: Thu Aug 24, 2017 11:11 pm

SCVVM Command freezing in Forms

Post by ITZBund_Ilmenau » Fri Sep 21, 2018 4:06 am

Product, version and build: PowerShell Studio 2018, v5.5.154
32 or 64 bit version of product: 64bit
Operating system: Windows Server 2016 (1607)
32 or 64 bit OS: 64bit
PS Engine: V5 - 64bit elevated with STA mode

I'm building a bunch of tools to simplify adding the whole network shebang for new subnets in SCVMM.

Code: Select all

	$SCVMMServer = "fqdn.of.scvmm.server"
	
	$LogicalNetwork = Get-SCLogicalNetwork -VMMServer $SCVMMServer -Name "INU-Datacenter_WORKNetwork"
	$LogicalNetworkDefinition = Get-SCLogicalNetworkDefinition -VMMServer $SCVMMServer -LogicalNetwork $LogicalNetwork -Name "INTEGRATION"
	$allSubnetVlans = $LogicalNetworkDefinition.SubnetVLans
	$newSubnetVLAN = New-SCSubnetVLan -VMMServer $SCVMMServer -Subnet "172.10.10.0/24" -VLanID "400"
	$allSubnetVlans += $newSubnetVLAN
	Set-SCLogicalNetworkDefinition -VMMServer $SCVMMServer -LogicalNetworkDefinition $LogicalNetworkDefinition -SubnetVLan $allSubnetVlans # this freezes
	Write-Host "this will never be reached in a form"
The main problem seems to be the command Set-SCLogicalNetworkDefinition.
Running this as a regular script (PS ISE or PSS) works as expected and the Write-Host will be displayed.
When run from a PSS form project, it will add the Subnet/Vlan to the network definition, but then freeze instead of continuing to the next line of code. This happens both from inside the PSS and after compiling.

User avatar
Alexander Riedel
Posts: 7049
Joined: Tue May 29, 2007 4:43 pm

Re: SCVVM Command freezing in Forms

Post by Alexander Riedel » Fri Sep 21, 2018 5:02 am

Write-host does nothing in a forms host. So you would not see that, ever.
Build an exe with a command line host and see if that command is somehow host specific.
In that case you would get an error message or a prompt.
It is also possible that this command wants to write to a console. Which a Windows app doesn't have.
It also would help to see where in a form you put that.
I am moving the post over to the PowerShell GUI sections, since this is not really a product issue.
Alexander Riedel
SAPIEN Technologies, Inc.

User avatar
Alexander Riedel
Posts: 7049
Joined: Tue May 29, 2007 4:43 pm

Re: SCVVM Command freezing in Forms

Post by Alexander Riedel » Fri Sep 21, 2018 5:02 am

[Topic moved by moderator]
Alexander Riedel
SAPIEN Technologies, Inc.

User avatar
ITZBund_Ilmenau
Posts: 13
Joined: Thu Aug 24, 2017 11:11 pm

Re: SCVVM Command freezing in Forms

Post by ITZBund_Ilmenau » Fri Sep 21, 2018 5:10 am

Write-Host does things.
When running inside the PSS, it will output to the Output window.
Also when you select the Script Engine "SAPIEN PowerShell Vx Host (Windows Application) it will direct all output like Write-Host or thrown errors to a separate "debugging" window.

Just create a new Forms project, add a button and insert the script (and set a proper SCVMM server address of course).
It will freeze at the describe command.
Run the same in a normal script and it works like a charm.

User avatar
Alexander Riedel
Posts: 7049
Joined: Tue May 29, 2007 4:43 pm

Re: SCVVM Command freezing in Forms

Post by Alexander Riedel » Fri Sep 21, 2018 5:23 am

The Windows application host is not a Forms host. Since you didn't specify the host, the assumption was that you used a forms host.
"Normal Script" is a 'flexible term'
A normal script from within Powershell Studio? Or from an elevated console?
Is elevation required? Did you try STA mode?
In general it would be better to post the complete code (as an attachment) rather than a snippet.
Alexander Riedel
SAPIEN Technologies, Inc.

User avatar
ITZBund_Ilmenau
Posts: 13
Joined: Thu Aug 24, 2017 11:11 pm

Re: SCVVM Command freezing in Forms

Post by ITZBund_Ilmenau » Sun Sep 23, 2018 10:37 pm

It doesn't matter if you select Windows Forms or Windows Application.
The thing I'm trying to get across here is that it doesn't work at all when you use a forms project.
If it helps, ignore the Write-Host and have it change a label or something. As long as it gets stuck on the Set-SCLogicalNetworkDefinition, it will never reach the next line, no matter what it would do.

As I wrote you can use the snippet I posted as a "normal script" both in PSS (PowerShell Studio) as well as the Powershell ISE. It will work.
Elevation is kinda required. Otherwise I'd just have to grab the credentials for SCVMM again within the form.
STA mode is enabled by default.

I thought the project is simple enough, but I've attached an example as requested (including the label change).
You'd still need a System Center Virtual Machine Manager and change up some values, though.
Attachments
test.zip
(39.15 KiB) Downloaded 29 times

User avatar
jvierra
Posts: 13790
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: SCVVM Command freezing in Forms

Post by jvierra » Sun Sep 23, 2018 11:04 pm

Have you tried to run this under the debugger? What line is it blocking on?

User avatar
ITZBund_Ilmenau
Posts: 13
Joined: Thu Aug 24, 2017 11:11 pm

Re: SCVVM Command freezing in Forms

Post by ITZBund_Ilmenau » Thu Sep 27, 2018 6:08 am

The onlything in the "Output" is:

Code: Select all

>> Debugging (test.psproj) Project Script...
>> Platform: V5 64Bit (STA) (Elevated) (Forced)
Until I forcefully kill it.

The "Debug Console" stays empty.

The line that makes it freeze is commented in the original code.

User avatar
jvierra
Posts: 13790
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: SCVVM Command freezing in Forms

Post by jvierra » Thu Sep 27, 2018 6:18 am

Did you set a breakpoint and step through the code to see which line is blocking?

Place a breakpoint on the first line of the code and click on the "Debug" button. When the BP is hit then "Step" over each line until it hangs,

User avatar
ITZBund_Ilmenau
Posts: 13
Joined: Thu Aug 24, 2017 11:11 pm

Re: SCVVM Command freezing in Forms

Post by ITZBund_Ilmenau » Thu Sep 27, 2018 10:45 pm

The blocking line is still the one mentioned.

The only thing that changed is the "Line breakpoint on ..." in the Tools Output and I now see all variables up to that point.
It still won't continue or give me any message that could help.

Locked