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.
This topic is 5 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
ITZBund_WisIT
Posts: 13
Last visit: Thu Mar 14, 2024 1:11 am

SCVVM Command freezing in Forms

Post by ITZBund_WisIT »

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: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: SCVVM Command freezing in Forms

Post by Alexander Riedel »

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: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: SCVVM Command freezing in Forms

Post by Alexander Riedel »

[Topic moved by moderator]
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
ITZBund_WisIT
Posts: 13
Last visit: Thu Mar 14, 2024 1:11 am

Re: SCVVM Command freezing in Forms

Post by ITZBund_WisIT »

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: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: SCVVM Command freezing in Forms

Post by Alexander Riedel »

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_WisIT
Posts: 13
Last visit: Thu Mar 14, 2024 1:11 am

Re: SCVVM Command freezing in Forms

Post by ITZBund_WisIT »

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 114 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: SCVVM Command freezing in Forms

Post by jvierra »

Have you tried to run this under the debugger? What line is it blocking on?
User avatar
ITZBund_WisIT
Posts: 13
Last visit: Thu Mar 14, 2024 1:11 am

Re: SCVVM Command freezing in Forms

Post by ITZBund_WisIT »

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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: SCVVM Command freezing in Forms

Post by jvierra »

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_WisIT
Posts: 13
Last visit: Thu Mar 14, 2024 1:11 am

Re: SCVVM Command freezing in Forms

Post by ITZBund_WisIT »

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.
This topic is 5 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked