如何从 Azure 的 Powershell 重新启动在 Azure ARM 订阅的自动化帐户的 Runbook 中运行的 AppService?
我认为方法是:
Restart-AzureWebsite -Name "your-appservice-name"
但这得到:
Restart-AzureWebsite : No default subscription has been designated.
Use select-AzureSubscription -Default #<subscriptionName> to set the default subscription.
Azure PowerShell 中没有可用的 Restart-AzureRmWebApp。
以下所有组合都会导致一堆其他错误消息:
$Cred = Get-AutomationPSCredential -Name 'your-credentials-name'
Add-AzureAccount -Credential $Cred
Add-AzureRMAccount -Credential $Cred
Get-AzureSubscription –SubscriptionName 'your-subscription-name' | Select-AzureSubscription -Default
Restart-AzureWebsite -Name "your-appservice-name"
最佳答案
There is no Restart-AzureRmWebApp available in Azure PowerShell.
正如Walter - MSFT提到的,我们可以导入AzureRM.Websites,在此之前我们需要将AzureRM.Profile
更新到4.0,更多详细内容可以引用截图。
在此之前,我们可以在本地创建 Azure AD 服务主体。 如何创建服务主体可以引用这个document
Login-AzureRmAccount
$sp = New-AzureRmADServicePrincipal -DisplayName exampleapp -Password "password"
Sleep 20
New-AzureRmRoleAssignment -RoleDefinitionName Contributor -ServicePrincipalName $sp.ApplicationId
在 Runbook 中运行 Restart-AzureRmWebApp 命令。
$azureAplicationId ="Application Id"
$azureTenantId= "tenant Id"
$azurePassword = ConvertTo-SecureString "password" -AsPlainText -Force
$psCred = New-Object System.Management.Automation.PSCredential($azureAplicationId , $azurePassword)
Add-AzureRmAccount -Credential $psCred -TenantId $azureTenantId -ServicePrincipal
Restart-AzureRmWebApp -ResourceGroupName "ResourceGroup" -Name "WebApp Name"
关于powershell - 如何从 Azure Powershell 重新启动 Azure 应用服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47298375/