Stp*_*111 2 powershell azure azure-automation
我完全没有使用 PowerShell 的经验 - 我想要做的是使用我的 Azure 自动化服务来设置一个 Runbook,它会在每晚凌晨 1 点自动重新启动我的一个 Azure Web 应用程序。
是否可以使用 Powershell/Azure 自动化来完成此操作?
这是完全可能的,您需要创建一个 Azure 自动化帐户,创建一个与计划相关的 Runbook 并使用如下内容:
$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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2634 次 |
| 最近记录: |