如何使用Start - AzureRmAutomationRunbook
powershell cmdlet
将哈希表传递给azure子Runbook?
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 localhostResult4:
True True String
System.Object localhost
这里出了什么问题?如何使用Start-AzureRmAutomationRunbook cmdlet
将哈希表正确传递给azure子Runbook?
提前Thanx!
此致 克里斯
答案 0 :(得分:1)
从“$ hash”中删除引文。通过添加引号,它将您的哈希表转换为字符串。试试这个:
$parameterHash = @{"Hash"=$Hash}