-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invoke-AzureRmVMRunCommand returns empty #5982
Comments
@mcocak Hey Mert, quick clarifying question: when you say that this was working last week, do you know if that was before or after you updated |
I didn't do an intended update to |
Also encountering this with the AzureRM modules (5.7.0 - April 2018). Update: After testing with -Debug it seems that the response does come back per below (message) however it doesn't output it on the Cmdlet. Rolled back to the AzureRM modules (5.6.0 - March 2018), all working again. Body: {
"startTime": "2018-04-22T12:57:03.0379341-05:00",
"endTime": "2018-04-22T12:57:46.3975869-05:00",
"status": "Succeeded",
"properties": {
"output": [
{
"code": "ComponentStatus/StdOut/succeeded",
"level": "Info",
"displayStatus": "Provisioning succeeded",
"message": "5.1"
},
{
"code": "ComponentStatus/StdErr/succeeded",
"level": "Info",
"displayStatus": "Provisioning succeeded",
"message": ""
}
]
},
"name": "**Removed**"
} |
This issue ended up breaking quite a few of our Azure runbooks after an automation account PowerShell module update. Troubleshooting finding: When only AzureRM.profile v4.5.0 and AzureRM.Compute v4.5.0 modules are imported in an Azure runbook or interactive PowerShell v5.1 session, the issue does not occur until only the AzureRM.profile module version is updated to v4.6.0. At that point, all properties are always null for any Invoke-AzureRmVMRunCommand PSRunCommandResult return object. |
Were you running this Cmdlet from a runbook of type PowerShell or PowerShell Workflow? I've seen that this returns empty when executed within a Workflow. Discussed the same with one of the Azure Automation Product group employees and it is expected that way in Workflows. If you want it to get proper output from it, run it within an |
Returns output in an Azure runbook of type Powershell (not workflow) when the AzureRM.profile module is v4.5. Does not return output in the same PowerShell runbook after update of AzureRM.profile module to v4.6. |
I confirm this breaking change, or bug if you will. In my particular case it breaks a VSTS provisioning pipeline where we verify the output before moving to the next step. I also confirm that moving back to 5.6.0 is a workaround. From the context of this issue I cannot really tell what is being done and when it will be fixed. Any update that you can share? |
There was a new release yesterday and the AzureRM.Compute module was also released as part of that. However, this issue still exists even in the latest release. We're also waiting for this to be fixed. |
As above. Any idea when this might be fixed? This has broken the majority of our Azure Automation Runbooks by updating to the latest AzureRM modules... :( |
Are there any updates on this at all? Preferably including an expected fix date...?! |
@jamesmealing As a temporary workaround, you can use the REST API. Rest API is working fine and returning expected output. So as a workaround, you can use that if it helps you. We're also using the same for the moment until this fix comes through. |
@hyonholee or @alpon, can you please take a look at this? This issue is a regression, as far as we can tell. |
@hyonholee, synced with @Aleksandair offline. Do you have an ETA that we can share? |
CC: @praries880 |
I can confirm the issue using the Invoke-AzureRMVmRunCommand with version 5.2.0 of the AzureRM.Computer PowerShell Module. I 'solved' the issue by creating my own PowerShell Function which calls the Azure REST API directly. Most important thing is that after calling the PUT request to run a command on the VM you need to receive a Response Header with location information to query the status of the first call. In my case I used Invoke-WebRequest instead of Invoke-RestMethod because the latter does not return a Response Header and Invoke-WebRequest does. Example code: #region Connect to Azure
Add-AzureRmAccount
#Select Azure Subscription
$Subscription =
(Get-AzureRmSubscription |
Out-GridView `
-Title 'Select an Azure Subscription ...' `
-PassThru)
Set-AzureRmContext -SubscriptionId $Subscription.Id -TenantId $Subscription.TenantID
#endregion
#region Get AccessToken
$currentAzureContext = Get-AzureRmContext
$azureRmProfile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile
$profileClient = New-Object -TypeName Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient -ArgumentList ($azureRmProfile)
$token = $profileClient.AcquireAccessToken($currentAzureContext.Subscription.TenantId)
#endregion
#region variables
$ResourceGroupName = 'STEFAN-D-RG'
$VMName = 'foo-d-web'
#endregion
#region we need to get a response header to retrieve the Azure-AsyncOperation
$APIVersion = '2017-12-01'
$Uri = 'https://management.azure.com/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Compute/virtualMachines/{2}/runCommand?api-version={3}' -f $Subscription.Id, $resourcegroupname, $VMName, $APIVersion
$Body = @{
'commandid' = 'RunPowerShellScript'
'script' = @('Get-Date')
'parameters' = @()
} | ConvertTo-Json -Compress
$params = @{
ContentType = 'application/json;charset=utf-8'
Headers = @{
'authorization' = "Bearer $($token.AccessToken)"
}
Method = 'Post'
URI = $Uri
Body = $Body
UseBasicParsing = $true
}
Invoke-WebRequest @params -OutVariable Result
#endregion
#region retrieve status of web request
$Result.Headers.Location
$Uri = $Result.Headers.Location
$params = @{
ContentType = 'application/json;charset=utf-8'
Headers = @{
'authorization' = "Bearer $($token.AccessToken)"
}
Method = 'Get'
URI = $Uri
}
$Status = $null
while (!($Status)) {
try {
$Status = Invoke-RestMethod @params
Start-Sleep 15
}
catch {
'Oops'
}
}
$Status
#endregion HTH cc @alexandair |
@praries880 Can you work with hyonho to ensure that this is fixed in the next milestone? |
This got fixed in #6720 |
Description
Invoke-AzureRmVMRunCommand started returning empty after execution. Until last week, the command printed the stdout of the remotely executed command on the VM. However, it is now returning empty string.
As you see in the debug output below, I'm executing a basic "docker ps" command on the remote Linux VM. The command is for sure executed remotely and the output of the command is visible in the HTTP response from Azure, however, Invoke-AzureRmVMRunCommand output is empty.
Script/Steps for Reproduction
Module Version
Environment Data
Debug Output
The text was updated successfully, but these errors were encountered: