powershell - 通过 Powershell 从 Azure RM 作业获取作业输入参数

标签 powershell azure azure-resource-manager

在使用 AzureRM 进行压力测试、配置和删除大块虚拟机期间,我们注意到我们的配置和删除 Runbook 上出现了一些奇怪的错误。我们希望有一个流程可以找到这些失败的作业并将其重新排队。为此,我们需要知道作业的输入参数。然而,当我们运行

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

所有作业的 jobParameters 计数均为 0。

这里是一些示例代码:

<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
    }
}

输出为:

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

我们做错了什么,看不到输入参数?无论作业状态如何,所有作业都显示 0 个作业参数。在 AzureRM 门户中查看同一作业时,我们可以看到以下参数:

  • MICROSOFTAPPLICATIONMANAGEMENTSTARTEDBY =“PowerShell”
  • VMNAME =“azrdevvmn125”

所以我们知道输入参数在那里,只是不知道如何通过 PowerShell 获取它们。如果您能提供任何帮助,我们将不胜感激。

谢谢!

最佳答案

仅当使用指定的作业 ID 参数调用 Get-AzureRmAutomationJob 且结果中有单个作业时,Get-AzureRmAutomationJob 才会返回 JobParameters 集合。您可以在 foreach 循环中尝试类似的操作:

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

$jobDetails 变量应填充 JobParameters 属性。

关于powershell - 通过 Powershell 从 Azure RM 作业获取作业输入参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35344776/

相关文章:

Azure列出所有实例REST API未在响应中返回提到的值

azure - 使用 ARM 完全自动化 Microsoft bot 框架部署(应用程序设置被删除且功能缺失)

azure - 如何通过 Bicep 将功能应用程序键添加到logicapp应用程序设置

Powershell - 当我使用 '>' 时,回车符插入到输出中

Azure Active Directory 角色管理

azure - 有什么方法可以获取 CloudBlobDirectory 实例的创建日期吗?

c# - 数据未插入到 Azure 上托管的 SQL Server 数据库中

powershell - 无法将对象转换为哈希表

powershell - PowerShell 中的 LDAP 查询

powershell - 使用 Get-Variable 返回的变量