我正在编写一个将在runbook中运行的powershell脚本。此脚本将首先禁用资源组中的功能应用程序,然后另一个类似的脚本将启用资源组中的功能应用程序。
我已经尝试过下面的脚本,但它没有启用功能应用程序
$connectionName = "AzureRunAsConnection"
try {
# Get the connection "AzureRunAsConnection "
$servicePrincipalConnection=Get-AutomationConnection -Name $connectionName
"Logging in to Azure..."
Add-AzureRmAccount `
-ServicePrincipal `
-TenantId $servicePrincipalConnection.TenantId `
-ApplicationId $servicePrincipalConnection.ApplicationId `
-CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint } catch {
if (!$servicePrincipalConnection)
{
$ErrorMessage = "Connection $connectionName not found."
throw $ErrorMessage
} else{
Write-Error -Message $_.Exception
throw $_.Exception
}
}
$RGName = Get-AutomationVariable -Name 'DRPrimaryResourceGroupName'
$FAppResources = Get-AzureRmResource -ResourceType "Microsoft.Web/sites" -ResourceGroupName $RGName -ExpandProperties
$LAppResources = Get-AzureRmResource -ResourceType "Microsoft.Logic/workflows" -ResourceGroupName $RGName -ExpandProperties
ForEach ($FAResource in $FAppResources) {
Write-Output ("*****************************************************************************************")
Write-Output ("Starting FunctionApp "+ $FAResource.ResourceName+ " in Resource Group " +$RGName)
Write-Output ("*****************************************************************************************")
Start-AzureRmWebApp -ResourceGroupName $RGName -Name $FAResource.ResourceName
Write-Output ($FAResource.ResourceName + " and its status is " + $FAResource.Properties.State)
}
ForEach ($LAResource in $LAppResources) {
Write-Output ("*****************************************************************************************")
Write-Output ("Enabling Logic App "+ $LAResource.ResourceName +" in Resource Group"+ $RGName)
Write-Output ("***************************************************************************************")
Set-AzureRmLogicApp -ResourceGroupName $RGName -Name $LAResource.ResourceName -State Enabled -Force
Write-Output ($LAResource.ResourceName + " and its status is " + $LAResource.Properties.State)
}