powershell - Start-AzureRmAutomationRunbook 不接受 System.String 参数

标签 powershell azure azure-automation

我正在尝试通过 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

如此处记录:Start-AzureRmAutomationRunbook cmdlet .

关于powershell - Start-AzureRmAutomationRunbook 不接受 System.String 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50818970/

相关文章:

powershell - 判断connect-msolservice是否已经被成功调用

powershell - 执行操作的访问权限不足 - Powershell

c# - 无法在 Azure 门户中查看通过 Visual Studio 创建/部署的函数的代码,但当我通过门户创建函数时可以查看代码

Azure AD 将 '#EXT#' 附加到 UserPrincipalName

azure - 如何在Azure中创建 "distinct"队列?

azure - Get-AzureRmVM 需要名称参数吗?

PowerShell从数据查询中获取CSV并添加列

powershell - 如何在powershell中[int]添加[string]正则表达式替换?

azure - Azure Stack 上的 Runbook 部署

azure - 计划工作簿无法识别我的 cmdlet 方法