Page 1 of 2

SCVVM Command freezing in Forms

Posted: Fri Sep 21, 2018 4:06 am
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.

Re: SCVVM Command freezing in Forms

Posted: Fri Sep 21, 2018 5:02 am
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.

Re: SCVVM Command freezing in Forms

Posted: Fri Sep 21, 2018 5:02 am
by Alexander Riedel
[Topic moved by moderator]

Re: SCVVM Command freezing in Forms

Posted: Fri Sep 21, 2018 5:10 am
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.

Re: SCVVM Command freezing in Forms

Posted: Fri Sep 21, 2018 5:23 am
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.

Re: SCVVM Command freezing in Forms

Posted: Sun Sep 23, 2018 10:37 pm
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.

Re: SCVVM Command freezing in Forms

Posted: Sun Sep 23, 2018 11:04 pm
by jvierra
Have you tried to run this under the debugger? What line is it blocking on?

Re: SCVVM Command freezing in Forms

Posted: Thu Sep 27, 2018 6:08 am
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.

Re: SCVVM Command freezing in Forms

Posted: Thu Sep 27, 2018 6:18 am
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,

Re: SCVVM Command freezing in Forms

Posted: Thu Sep 27, 2018 10:45 pm
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.