从Automation脚本(RunBook)运行Set-AzureRmAppServicePlan

时间:2016-01-25 03:29:50

标签: powershell azure azure-web-app-service

我正在尝试从自动化Runbook运行Set-AzureRmAppServicePlan但是获取

  

Set-AzureRmAppServicePlan:运行Login-AzureRmAccount进行登录。在   line:20 char:1   + Set-AzureRmAppServicePlan -ResourceGroupName“......   + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~       + CategoryInfo:InvalidOperation:(:) [Set-AzureRMAppServicePlan],PSInvalidOperationException       + FullyQualifiedErrorId:InvalidOperation,Microsoft.Azure.Commands.WebApps.Cmdlets.AppServicePlans.SetAzureAppServicePlanCmdlet

请注意,使用Automation Credential的实际Runbook身份验证是成功的。 我可以使用本地PowerShell运行此脚本 登录-AzureRmAccount 附加AzureRmAccount 设置AzureRmAppServicePlan ...

是否可以在没有交互式登录的情况下从自动化中运行此操作? 谢谢 帕维尔

2 个答案:

答案 0 :(得分:0)

弄清楚..非常简单而不是

Add-AzureAccount - 用于自动创建的示例Runbook Get-AzureVMTutorial

需要使用

...添加-AzureRmAccount

用于Azure Resource Manager cmdlet请求,例如 设置AzureRmAppServicePlan

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

答案 1 :(得分:0)

如果您没有使用MFA,请参阅以下内容,替换“您的密码”,“您的用户名”,“您的环境”,“#SubscriptionId”和“#SubscriptionId&#” 39;,' 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'
相关问题