Friday, March 12, 2021

PowerShell for Scale Up and Scale down service plan on Azure - Runbook

 If as azure admin you want to scale up and scale down your azure service plan environment during the weekend for saving a cost so this power shell can help you to create runbook


Main Command


Set-AzureRMAppServicePlan -Tier Standard -Name "serviceplanname" -ResourceGroupName "nameoftheresource"

Specifically:

-Tier identifies the type of Tier that we want to set: free, shared, basic, standard or premium

-Name allows us to specify the type of Tier we need, for example if the Tier is Standard, the Name could be S1, S2 or S3

Tier parameter

Free  - F1

Shared - D1

Basic = B1

Standard = S

Premium  = P

You can use below Script in runbook. Change the value for $resourceGroupName  and $appServiceName and pass the -Tier Free\Shared\Basic

 

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

$resourceGroupName = "XXXXXXXX"
$appServiceName = "XXXXXX"
 
filter timestamp {"[$(Get-Date -Format G)]: $_"}
Write-Output "Script started." | timestamp
 
#Authenticate with Azure Automation Run As account (service principal)  
$runAsConnectionProfile = Get-AutomationConnection `
-Name "AzureRunAsConnection"
Add-AzureRmAccount -ServicePrincipal `
-TenantId $runAsConnectionProfile.TenantId `
-ApplicationId $runAsConnectionProfile.ApplicationId `
-CertificateThumbprint ` $runAsConnectionProfile.CertificateThumbprint | Out-Null
Write-Output "Authenticated with Automation Run As Account."
 
#Modifying size of AppService Plan
Set-AzureRMAppServicePlan -Tier Free -Name "HendtestAppSerplan" -ResourceGroupName "RG-Dormakaba"
# Get the App Service object and show its new state
$appService = Get-AzureRmAppServicePlan -ResourceGroupName $resourceGroupName -Name $appServiceName
Write-Output "App Service Plan name: $($appService.Name)" | timestamp

Write-Output "Current App Service Plan status: $($appService.Status), tier: $($appService.Sku.Name)" | timestamp

 

 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


Reference Link : https://techoosolutions.wordpress.com/2017/02/02/change-azure-appserviceplan/