1

During our stress-tests with AzureRM, provisioning and deleting large blocks of VMs, we noticed that we get some odd errors on our provisioning and delete runbooks. We'd like to have a process that finds these failed jobs and re-queues them. In order to do that, we need to know the job's input parameters. However, when we run

Get-AzureRmAutomationJob -AutomationAccountName $aa.AutomationAccountName -RunbookName "Delete-AzureRmVm" -StartTime $then -Status "Failed" -ResourceGroupName $rg.ResourceGroupName

all of the jobs show a count of 0 for the jobParameters.

Here is some sample code:

<code to get assets>
$suspended = Get-AzureRmAutomationJob -AutomationAccountName $aa.AutomationAccountName -RunbookName "Delete-AzureRmVm" -StartTime $then -Status "Suspended" -ResourceGroupName $rg.ResourceGroupName
$failed = Get-AzureRmAutomationJob -AutomationAccountName $aa.AutomationAccountName -RunbookName "Delete-AzureRmVm" -StartTime $then -Status "Failed" -ResourceGroupName $rg.ResourceGroupName
$completed = Get-AzureRmAutomationJob -AutomationAccountName $aa.AutomationAccountName -RunbookName "Delete-AzureRmVm" -StartTime $then -Status Completed -ResourceGroupName $rg.ResourceGroupName

foreach($job in $completed)
{
    Write-Output " "
    $job
    Write-Output " "
    $jobId = $job.JobId.Guid.ToString()
    Write-Output "Job Parameters for $jobId"
    #Get-AzureRmAutomationJobOutput -Id $job.JobId -Stream Any -ResourceGroupName $rg.ResourceGroupName -AutomationAccountName $aa.AutomationAccountName -Verbose
    foreach($jobParameter in $job.JobParameters)
    {
        $jobParameter
        break
    }
}

The output is:

ResourceGroupName      : <valid RGN>
AutomationAccountName  : <valid AAN>
JobId                  : 2b5fdc91-c87b-4704-9b12-91d2365eaa95
CreationTime           : 2/10/2016 5:19:38 PM -05:00
Status                 : Completed
StatusDetails          : 
StartTime              : 2/10/2016 5:19:42 PM -05:00
EndTime                : 2/10/2016 5:43:25 PM -05:00
Exception              : 
LastModifiedTime       : 2/10/2016 5:43:25 PM -05:00
LastStatusModifiedTime : 1/1/0001 12:00:00 AM +00:00
JobParameters          : {}
RunbookName            : Delete-AzureRmVm
HybridWorker           : 
StartedBy              : 


Job Parameters for 2b5fdc91-c87b-4704-9b12-91d2365eaa95

What are we doing wrong that we don't see the input parameters? Regardless of job status, all jobs are showing 0 job parameters. When looking at the same job in the AzureRM Portal, we can see the following parameters:

  • MICROSOFTAPPLICATIONMANAGEMENTSTARTEDBY = "PowerShell"
  • VMNAME = "azrdevvmn125"

So we know that the input parameters are there, just not how to get to them via PowerShell. Any help you can provide would be greatly appreciated.

Thanks!

DLaMana
  • 31
  • 1
  • 4

1 Answers1

1

Get-AzureRmAutomationJob returns JobParameters collection only when it is called with a job ID parameter specified and there is a single job in the result. You can try something like this inside the foreach loop:

$jobDetails = Get-AzureRmAutomationJob -AutomationAccountName $aa.AutomationAccountName -ResourceGroupName $rg.ResourceGroupName -Id $job.Id

The $jobDetails variable should have JobParameters property filled.

SergVro
  • 721
  • 1
  • 6
  • 9