Hi all,
I have a script:
$creds = Get-Credential
Login-AzureRmAccount -Credential $creds -ServicePrincipal -TenantId 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
$VMname = "xx-xx-xxxxx"
$ResourceGroupName = "xxxxxx"
Start-AzureRmVm -ResourceGroupName $ResourceGroupName -Name $VMname
This script runs fine as a script and my VMware machine is started. But when I use the exact same code in the GUI it doesn't work. I don't get an error, script just freezes.
Hope that someone has a solution for this.
Greetings,
Sander
Different script execution between GUI and Non-GUI
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.
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.
Re: Different script execution between GUI and Non-GUI
Have you stepped through with the debugger to see where it is hanging?
How are you running it in the form? Is it a button or some other control or event?
How are you running it in the form? Is it a button or some other control or event?
- UsernameIsAlreadyTaken
- Posts: 2
- Last visit: Thu Jun 29, 2017 7:49 pm
Re: Different script execution between GUI and Non-GUI
This started doing this for me too, which is how I found this post while searching around for a fix. At least I know it's not me or my local machine.
The Start-AzureRmVm line just freezes forever. All other lines before it setting up the Start-AzureRmVm line work. There are no buttons like the other guy asked, just real simple code like in your example.
You're actually more lucky than me, as it locks up no matter if I run the line in the gui or not. The vm starts fine, but it totally locks up powershell, breaking or hitting the stoprun button doesn't unfreeze it. I have to totally kill powershell to get out of it. It used to work a few weeks ago, so M$ must have made a change that locks it up. Like you, I sure hope somebody finds a solution.
BTW, what location is your vm in? Mine is in West US 2, and it seems to take an abnormal amount of time to start and stop the vm.
The Start-AzureRmVm line just freezes forever. All other lines before it setting up the Start-AzureRmVm line work. There are no buttons like the other guy asked, just real simple code like in your example.
You're actually more lucky than me, as it locks up no matter if I run the line in the gui or not. The vm starts fine, but it totally locks up powershell, breaking or hitting the stoprun button doesn't unfreeze it. I have to totally kill powershell to get out of it. It used to work a few weeks ago, so M$ must have made a change that locks it up. Like you, I sure hope somebody finds a solution.
BTW, what location is your vm in? Mine is in West US 2, and it seems to take an abnormal amount of time to start and stop the vm.
Re: Different script execution between GUI and Non-GUI
What threading model are you using? What version of WMF?
More information would help to find a solution although many PS modules cannot be run from GUI.
More information would help to find a solution although many PS modules cannot be run from GUI.
- UsernameIsAlreadyTaken
- Posts: 2
- Last visit: Thu Jun 29, 2017 7:49 pm
Re: Different script execution between GUI and Non-GUI
I've answered my own question, I hate it when I do that! (OK, actually I don't... )
start-job {
$creds = Get-Credential
Login-AzureRmAccount -Credential $creds -ServicePrincipal -TenantId 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
$VMname = "xx-xx-xxxxx"
$ResourceGroupName = "xxxxxx"
Start-AzureRmVm -ResourceGroupName $ResourceGroupName -Name $VMname
}
This will pull up the login prompt for you, and then lets the Start-AzureRmVm lock up in the background, yuk, yuk. Don't try to 'stop-job' afterwards, it locks powershell up again...
start-job {
$creds = Get-Credential
Login-AzureRmAccount -Credential $creds -ServicePrincipal -TenantId 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
$VMname = "xx-xx-xxxxx"
$ResourceGroupName = "xxxxxx"
Start-AzureRmVm -ResourceGroupName $ResourceGroupName -Name $VMname
}
This will pull up the login prompt for you, and then lets the Start-AzureRmVm lock up in the background, yuk, yuk. Don't try to 'stop-job' afterwards, it locks powershell up again...
Re: Different script execution between GUI and Non-GUI
No one has mentioned "Start-Job" in this thread. If you have an issue with this then please open a new thread with the details of your issue. This user has a different issue.
- andylyonette
- Posts: 4
- Last visit: Tue Jan 11, 2022 2:03 pm
Re: Different script execution between GUI and Non-GUI
I'm seeing the same issue with Get-AzureRmRoleAssignment - just locked up the app.
If I run it in debug mode I can see it gets stuck straight away:
DEBUG: 17:44:38 - GetAzureRoleAssignmentCommand begin processing with ParameterSet 'ScopeWithSignInNameParameterSet'.
DEBUG: 17:44:38 - using account id '###UserID###'..
compared with just running it in a PS console window:
DEBUG: 17:49:47 - GetAzureRoleAssignmentCommand begin processing with ParameterSet 'ScopeWithSignInNameParameterSet'.
DEBUG: 17:49:48 - using account id '##UserId###'...
DEBUG: [Common.Authentication]: Authenticating using Account: '###UserID###, environment: 'AzureCloud', tenant: '###TenantID###'
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
...... and so on
The user is prompted to log into Azure interactively using Login-AzureRmAccount and other Azure cmdlets such as Get-AzureRmSubscription work fine.
I'm running Windows 10 Pro build 15063 x64 and have tested with multiple version of the PowerSHell module released this year. What do I need to do next to try and narrow this down further?
Thanks,
Andy
If I run it in debug mode I can see it gets stuck straight away:
DEBUG: 17:44:38 - GetAzureRoleAssignmentCommand begin processing with ParameterSet 'ScopeWithSignInNameParameterSet'.
DEBUG: 17:44:38 - using account id '###UserID###'..
compared with just running it in a PS console window:
DEBUG: 17:49:47 - GetAzureRoleAssignmentCommand begin processing with ParameterSet 'ScopeWithSignInNameParameterSet'.
DEBUG: 17:49:48 - using account id '##UserId###'...
DEBUG: [Common.Authentication]: Authenticating using Account: '###UserID###, environment: 'AzureCloud', tenant: '###TenantID###'
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
...... and so on
The user is prompted to log into Azure interactively using Login-AzureRmAccount and other Azure cmdlets such as Get-AzureRmSubscription work fine.
I'm running Windows 10 Pro build 15063 x64 and have tested with multiple version of the PowerSHell module released this year. What do I need to do next to try and narrow this down further?
Thanks,
Andy
Re: Different script execution between GUI and Non-GUI
The outstanding question is still - What threading model are you using.
Also simplify this to a simple form with one button. Cop script to clipboard and paste into CLI PowerShell. Does the same thing happen?
Also simplify this to a simple form with one button. Cop script to clipboard and paste into CLI PowerShell. Does the same thing happen?