Woody Chan
Woody Chan

Reputation: 69

Run Command on Virtual Machine failing & preventing other 'Invoke-AzureRmVMRunCommand'

Problem: When I run a Powershell runbook with an 'Invoke-AzureRmVMRunCommand' on an Azure Windows VM, and I have to STOP the runbook because of an error in the invoked command (and it idles forever), all new repetitions of the runbook fail with "Run command extension execution is in progress. Please wait for completion before invoking a run command.".

This is the runbook statement to have a PS script running on the VM:

Invoke-AzureRmVMRunCommand -ResourceGroupName $objVM.ResourceGroupName -Name $objVM.Name -CommandId 'RunPowerShellScript' -ScriptPath $strRemoteScriptFileNameTmp -Parameter $hshParams

The PS code in '$strRemoteScriptFileNameTmp' has this statement in it, which makes the runbook idling, ,i.e. need to be fixed:

Invoke-Expression -Command "$strRunTimeEnv $strExecPath $strExecParaString"

The -Command then looks as this; it shall install that ODBC driver to the VM, and works when executed with the PS CLI of the VM (RDP'd):

msiexec.exe /quiet /passive /qn /norestart /l* D:\msodbcsql_13.0_x64.log /package D:\UpdateODBC\Application\Live\msodbcsql_13.0_x64.msi IACCEPTMSODBCSQLLICENSETERMS=YES ADDLOCAL=ALL

Question: I know there is a timeout of 90 minutes for that (orphaned) command of the runbook. But, where is this idling, on the VM or the Automation Account? And, how can I kill it? It seems ridiculous to wait for 90 minutes before a new attempt to run the runbook can be made.

(I am not exactly get into a productive workflow here the way Msft have set this up... And yes, I read the posts on this topic already, and also the Msft docs which really need proof-reading by an English speaker, btw.)

Upvotes: 0

Views: 4417

Answers (2)

Andrew Stiver
Andrew Stiver

Reputation: 1

Microsoft has released a newer version of Invoke-AzVMRunCommand called Set-AzVMRunCommand, which adds some functionality that will allow it to circumvent this issue:

  • Parallel execution of multiple scripts
  • Includes Remove-AzVMRunCommand, which can be used to terminate script execution of in-progress scripts

Upvotes: 0

Woody Chan
Woody Chan

Reputation: 69

To conclude this I just like to share what I was given by MSDN in their answer:

"...Invoke-AzureRmVMRunCommand is actually using a REST command to send a powershell script to the VM..."

"There are restrictions on what can be done via this method:

  • One script at a time can run.
  • You can't cancel a running script.
  • The maximum time a script can run is 90 minutes. After that, it will time out. "

See: [https://learn.microsoft.com/en-us/azure/virtual-machines/windows/run-command#restrictions][1]

Best!

Upvotes: 1

Related Questions