【发布时间】:2020-03-11 09:06:10
【问题描述】:
我正在尝试编写一些简单的 Powershell 脚本来停止、启动和重新启动我们的 Azure Web 应用程序。我可以看到有名为Stop-AzWebApp、Start-AzWebApp 和Restart-AzWebApp 的cmdlet 可以执行此操作。问题是它们都需要一个名为 DefaultProfile 的参数,类型为 Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer。我如何掌握这个?
我四处寻找解决方案,但似乎令人困惑,因为似乎有几种方法可以做到这一点,包括调用Connect-AzAccount,但这需要多个参数(我不确定我需要提供哪些参数)。
这是我从 TFS 构建中调用 Get-AzSubscription 时遇到的错误。
这是我从 TFS 构建中调用 Stop-AzWebApp 时遇到的错误。
No subscription found in the context Please ensure that the credentials you provided are authorized to access the Azure subscription then run Connect-AzAccount to login
这是我正在使用的 PS 脚本。
$ResourceGroupName = "MyResourceGroup"
$Name = "MyWebAppName"
"Stopping web application " + $Name
"ResourceGroupName: " + $ResourceGroupName
"Name: " + $Name
$SubscriptionId = "xxxx-xxxx-xxxx-xxxx"
"SubscriptionId is: " + $SubscriptionId
$Subscription = Get-AzSubscription -SubscriptionId $SubscriptionId
"Subscription : " + $Subscription
Stop-AzWebApp -ResourceGroupName $ResourceGroupName -Name $Name
启动、停止和重新启动 Azure Web 应用程序的最简单方法是什么?
【问题讨论】:
标签: powershell azure-web-app-service azure-powershell