Page 1 of 1

Forms which use certain Azure PS commands hang

Posted: Mon Oct 02, 2017 12:16 pm
by rbeuthin2
Product, version and build: PowerShell Studio 2017, 5.4.143
32 or 64 bit version of product: 64-bit
Operating system: Windows 7
32 or 64 bit OS: 64-bit

A few other posts have raised this topic (see end of post for links) but seem to have been abandoned with no definitive answer. The problem is that when using certain Azure cmdlets in a form, the form will hang (sometimes, which I'll get to below) whereas using them in a script with no GUI works all the time. The strange thing is, the form does occasionally work. And once it starts working, it keeps working for hours and will then stop working again, usually if you leave it for a few hours and then return.

The problem can be very easily replicated with this code below in a form with a single button:
$button1_Click={
$creds = Get-Credential
Login-AzureRmAccount -Credential $creds
Get-AzureRmADGroup #This command will hang
Get-AzureRmKeyVault #This command will work
}

I have tried with STA on/off and v5/v4 and the behaviour is consistent (except for when it mysteriously decides to work for a while). Also tried on Windows 7 and Windows Server 2016 with same result.

In stepping through the code it seems to hang as it enters the AzureRm.Profile.psd1 file at the point where the Debug output says "Using account id <username>".

Any insight/solutions would be very welcome as there is no shortage of GUI-style scripts that you can write once you start using Azure and this is a big roadblock to doing that.

Other posts which touch on same topic:
viewtopic.php?f=21&t=10903
viewtopic.php?f=21&t=11626

Re: Forms which use certain Azure PS commands hang

Posted: Mon Oct 09, 2017 1:19 pm
by Alexander Riedel
That is really a question you should pose to the Azure team. Unfortunately we have no access to their code.
Most likely they make an assumption somewhere that the host has a console, which a Windows forms application does not have.
When they try to get access to the console they get a null object and just fail to handle that. But that is really just a guess on my side.