powershell - 如何从 Azure Powershell 重新启动 Azure 应用服务

标签 powershell azure azure-web-app-service

如何从 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,更多详细内容可以引用截图。

enter image description here

在此之前,我们可以在本地创建 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" 

enter image description here

关于powershell - 如何从 Azure Powershell 重新启动 Azure 应用服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47298375/

相关文章:

powershell - 在 PowerShell 中使用 "Backup"上下文创建卷影副本

powershell - 创建一个在路径中开始的 Powershell 快捷方式

laravel - Microsoft Azure 符号链接(symbolic link)存储文件夹 Laravel

asp.net-mvc - Facebook、Google OAuth 在 Azure 上有时会失败

node.js - Azure "Web apps"服务 : auto-install npm modules from package. json

powershell - 如何在 PowerShell 中连接值?

powershell - 可变音译(powershell)

azure - 可以通过 Azure CLI 部署创建和删除 databricks 资源

azure - 在 Azure 数据工厂中格式化 utcnow()

c# - 从azure网站访问证书时 key 集不存在