0

如何使用 Start- AzureRmAutomationRunbookpowershell将哈希表传递给 azure child runbook cmdlet

我有两个运行手册,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

结果3:

结果4:

IsPublic IsSerial Name BaseType
PSComputerName
-------- -------- ---- -------- -------------- True True String System.Object 本地主机

结果4:

True True 字符串
System.Object localhost

结果4:

True True 字符串
System.Object localhost


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

提前谢谢!

问候,克里斯

4

1 回答 1

1

从“$hash”中删除引号。通过添加引号,它把你的哈希表变成了一个字符串。尝试这个:

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

于 2018-01-23T18:18:54.113 回答