运行 来自自动化脚本 (RunBook) 的 Set-AzureRmAppServicePlan

Running Set-AzureRmAppServicePlan from Automation script (RunBook)

我正在尝试 运行 来自自动化的 Set-AzureRmAppServicePlan 运行book 但得到

Set-AzureRmAppServicePlan : Run Login-AzureRmAccount to login. At line:20 char:1 + Set-AzureRmAppServicePlan -ResourceGroupName "... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [Set-AzureRMAppServicePlan], PSInvalidOperationException + FullyQualifiedErrorId : InvalidOperation,Microsoft.Azure.Commands.WebApps.Cmdlets.AppServicePlans.SetAzureAppServicePlanCmdlet

请注意,使用 Automation Credential 的实际 运行图书身份验证是成功的。 我可以 运行 从本地 powershell 使用这个脚本 登录-AzureRmAccount 添加-AzureRmAccount 设置 AzureRmAppServicePlan...

是否有可能 运行 在没有交互式登录的情况下从自动化中做到这一点? 谢谢 帕维尔

弄清楚.. 比

更简单

Add-AzureAccount - 在自动创建的示例 Runbook Get-AzureVMTutorial 中使用

需要使用

Add-AzureRmAccount

用于 Azure 资源管理器 cmdlet 请求,例如 Set-AzureRmAppServicePlan

在这里留下问题/答案..可能仍然对某人有帮助

如果您没有使用 MFA,请查看以下命令,将 'yourPassword'、'yourUserName'、'yourEnvironment'、'yourSubscriptionId'、'yourTenantId' 替换为您的自己的消息并将其放入您的脚本,然后您可以在没有交互式页面的情况下登录。

$userPassword = ConvertTo-SecureString -String "yourPassword" -AsPlainText -Force
$psCred = new-object -typename System.Management.Automation.PSCredential -argumentlist 'yourUserName', $userPassword
$credential = Get-Credential -Credential $psCred
add-azureRmAccount -EnvironmentName 'yourEnvironment' -credential $credential -subscriptionId 'yourSubscriptionId' -tenant 'yourTenantId'