4

I'm using a 'Basic' plan. I want to create a script which can switch 'always-on' to false, then change the service plan to the free tier. When I need the function again I can reverse the settings. Why am I doing this? So I can ensure the App service plan keeps the same outbound IP addresses. I don't want to be paying for a Basic plan all the time so a simple script to do this is required.

I am using the latest 'AZ' modules.

$site = Get-AzWebApp -ResourceGroupName $ResourceGroupName -Name  $SiteName
$site.SiteConfig.AlwaysOn = $false

Set-AzWebApp -ResourceGroupName $ResourceGroupName -Name $SiteName ???

Thanks

Andrew Jocelyn
  • 399
  • 1
  • 3
  • 18

2 Answers2

3

Setting App Service Plan

Set-AzAppServicePlan -ResourceGroupName "myrgname"  -Name "my app service plan name" -Tier Basic -WorkerSize Small

For Free, you can change the Tier name to Free

Setting Always On

Connect-AzAccount

$webApp = Get-AzResource -ResourceType 'microsoft.web/sites' -ResourceGroupName 'myrgname' -ResourceName 'my function app name'

$webApp | Set-AzResource -PropertyObject @{"siteConfig" = @{"AlwaysOn" = $false}}

Here are two other similar SO posts.. difference is they don't tackle App Service Plan tier changes or make use of the latest Az modules Post1 and Post2

Rohit Saigal
  • 9,317
  • 2
  • 20
  • 32
2

You can simply pipe the modified application to Set-AzWebApp.

$app = Get-AzWebApp -ResourceGroupName $ResourceGroupName -Name $ApplicationName
$app.SiteConfig.AlwaysOn = $false
$app | Set-AzWebApp
David Peden
  • 17,596
  • 6
  • 52
  • 72