我正在尝试通过 Azure 自动化为 Azure 中的一个环境自动重新启动服务器。 我创建了一本运行手册来了解有多少服务器在线。 然后尝试将输出作为参数传递给另一个 Runbook 并获取 错误。
下面是代码。
$connectionName = "AzureRunAsConnection"
try
{
# Get the connection "AzureRunAsConnection "
$servicePrincipalConnection=Get-AutomationConnection -Name $connectionName
"Logging in to Azure..."
Add-AzureRmAccount `
-ServicePrincipal `
-TenantId $servicePrincipalConnection.TenantId `
-ApplicationId $servicePrincipalConnection.ApplicationId `
-CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint
}
catch {
if (!$servicePrincipalConnection)
{
$ErrorMessage = "Connection $connectionName not found."
throw $ErrorMessage
} else{
Write-Error -Message $_.Exception
throw $_.Exception
}
}
$Output = @()
$Running_XenApps = @()
$Output = .\Test.ps1
Foreach ($out in $Output)
{
$Running_XenApps += $out.Name | Out-String
}
Start-AzureRmAutomationRunbook –AutomationAccountName 'acm2eo-azure- automation' -Name 'Server-Reboot' -ResourceGroupName 'acm2eo-automation' -Parameters $Running_Xenapps -Runon acm2eo-hybrid-group1
我遇到以下错误。
Start-AzureRmAutomationRunbook : Cannot convert 'System.Object[]' to the type 'System.Collections.IDictionary' requiredby parameter 'Parameters'. Specified method is not supported.
请告诉我如何转换它。
提前致谢。
最佳答案
您必须将哈希表/字典传递给-Parameter
参数:
$params = @{
"YourParameterName" = $Running_XenApps
}
Start-AzureRmAutomationRunbook –AutomationAccountName 'acm2eo-azure- automation' -Name 'Server-Reboot' -ResourceGroupName 'acm2eo-automation' -Parameters $params -Runon acm2eo-hybrid-group1
关于powershell - Start-AzureRmAutomationRunbook 不接受 System.String 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50818970/