如何使用Start-AzureRmAutomationRunbook powershell cmdlet将哈希表传递给azure子Runbook?

时间:2018-01-04 09:28:41

标签: powershell azure workflow runbook

如何使用Start - AzureRmAutomationRunbook powershell cmdlet将哈希表传递给azure子Runbook?

我有两个runbook,test1和test2:

workflow test1
    {
    $Conn = Get-AutomationConnection -Name AzureRunAsConnection
    Add-AzureRMAccount -ServicePrincipal -Tenant $Conn.TenantID -ApplicationId $Conn.ApplicationID -CertificateThumbprint $Conn.CertificateThumbprint 

    $Hash = @{"ping"="pong"}
    $parameterHash = @{"Hash"="$Hash"}

    Start-AzureRmAutomationRunbook `
        -ResourceGroupName "rg1" `
        -AutomationAccountName "ac1" `
        -Name "test2" `
        -Parameters $parameterHash 
    }
workflow test2
    {
    Param
        (  
        [Object]$Hash
        )     
        "Result1:"
        $Hash

        InlineScript {
            $Hash = $using:Hash

            "Result2:"
            $Hash

            "Result3:"
            foreach ($h in $Hash.GetEnumerator()) {
            Write-Host "$($h.Name): $($h.Value)"

            "Result4:"
            $HashType = $Hash.GetType()
            $HashType
            }
    }
}

当我运行Runbook test1时,Runbook test2的结果是:

  

结果1:

     

System.Collections.Hashtable

     

结果2:

     

System.Collections.Hashtable

     

Result3:

     

Result4:

     

IsPublic IsSerial Name BaseType
  PSComputerName
  -------- -------- ---- -------- -------------- True True String System.Object localhost < / p>      

Result4:

     

True True String
  System.Object localhost

     

Result4:

     

True True String
  System.Object localhost

这里出了什么问题?如何使用Start-AzureRmAutomationRunbook cmdlet将哈希表正确传递给azure子Runbook?

提前Thanx!

此致 克里斯

1 个答案:

答案 0 :(得分:1)

从“$ hash”中删除引文。通过添加引号,它将您的哈希表转换为字符串。试试这个:

$parameterHash = @{"Hash"=$Hash}