Azure 自动化 - 每天自动重启 Web 应用程序的运行手册

Azure Automation - Runbook to auto-restart a web app once a day

我对 PowerShell 没有太多经验 - 我想做的是使用我的 Azure 自动化服务来设置一个 runbook,它会在每晚凌晨 1 点自动重启我的一个 Azure Web 应用程序。

是否可以通过 Powershell/Azure 自动化来完成此操作?

这是完全可能的,您需要创建一个 Azure 自动化帐户,创建一个绑定到计划的运行手册并使用类似这样的东西:

$connectionName = "AzureRunAsConnection" # this is the default connection created when you provision the Automation account,
                                         # you might need to change this to your own connection name
$servicePrincipalConnection = Get-AutomationConnection -Name $connectionName         

$null = Add-AzureRmAccount `
    -ServicePrincipal `
    -TenantId $servicePrincipalConnection.TenantId `
    -ApplicationId $servicePrincipalConnection.ApplicationId `
    -CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint

$null = Select-AzureRmSubscription -SubscriptionId 'SUB_GUID' ` # Needed if you have more than 1 subscription

Restart-AzureRmWebApp -ResourceGroupName xxx -Name WebAppName