如何从Azure Powershell重新启动Azure appservice
如何从Azure中ARM订阅的自动化帐户中的Runbook中运行的Azure Powershell重新启动AppService 我认为方法是:如何从Azure Powershell重新启动Azure appservice,powershell,azure,azure-web-app-service,Powershell,Azure,Azure Web App Service,如何从Azure中ARM订阅的自动化帐户中的Runbook中运行的Azure Powershell重新启动AppService 我认为方法是: Restart-AzureWebsite -Name "your-appservice-name" 但这会得到: Restart-AzureWebsite : No default subscription has been designated. Use select-AzureSubscription -Default #<subscript
Restart-AzureWebsite -Name "your-appservice-name"
但这会得到:
Restart-AzureWebsite : No default subscription has been designated.
Use select-AzureSubscription -Default #<subscriptionName> to set the default subscription.
此Powershell脚本在Azure自动化运行手册中工作:
Invoke-AzureRmResourceAction -ResourceGroupName "<your-resource-group-name>" -ResourceName "<your-resource-name>" -ResourceType 'Microsoft.Web/sites' -Action 'Restart' -Force
调用AzureRmResourceAction-ResourceGroupName”“-ResourceName”“-ResourceType'Microsoft.Web/sites'-Action'Restart'-Force
编辑
然而,下一个脚本可能更好;它依赖于@Tom Sun的上述答案,即
$Cred = Get-AutomationPSCredential -Name '<your-credentials>'
Add-AzureRMAccount -Credential $Cred
Get-AzureRmSubscription –SubscriptionName '<your-subscription-name>' | Select-AzureRmSubscription
Restart-AzureRmWebApp -ResourceGroupName "office" -Name "<your-appservice-name>"
$Cred=获取自动PSCredential-名称“”
添加AzureRMAccount-凭证$Cred
获取AzureRmSubscription–SubscriptionName“”;选择AzureRmSubscription
重新启动AzureRmWebApp-ResourceGroupName“office”-名称“”
AzureRM.Profile
更新到4.0,更多详细信息请参考屏幕截图
在此之前,我们可以在本地创建Azure广告服务主体。
如何创建服务主体我们可以参考以下内容
在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"
重新启动AzureWeb
这是一个经典的cmdlet。你的Azure Power Shell版本是什么Get Module-listavable-Name Azure-Refresh
该命令甚至不在Azure Powershell中运行;它返回:runbook作业尝试了3次,但每次都失败。此处可以找到runbook作业失败的常见原因:在runbook中,您需要导入模块AzureRM.Websites
,导入模块AzureRM.Websites导致:导入模块:未加载指定模块“AzureRM.Websites”,因为在任何模块目录中都找不到有效的模块文件。您好,您只需要将模块导入到您的自动化帐户,然后就可以使用cmdlet。无需在您的runbook中使用导入模块AzureRm.Websites
。这些命令(登录AzureRmAccount和重新启动AzureRmWebApp)在runbook中都不可用。我已更新了如何为自动化帐户添加模块的答案。
Login-AzureRmAccount
$sp = New-AzureRmADServicePrincipal -DisplayName exampleapp -Password "password"
Sleep 20
New-AzureRmRoleAssignment -RoleDefinitionName Contributor -ServicePrincipalName $sp.ApplicationId
$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"