Tuesday, November 19, 2019

How to upscale and downscale the VMSS using powershell?

Today, I am gonna discuss about how we can increase/ decrease the count of machines in a VMSS in Azure. This script can be extremely useful while using the AzureDevops pipeline for scaling the VMSS.
I have used this script for changing the count of the number of machines depending the number of test cases to executed(in automated testcases).

Below is script:

$resourceGroup = "Enter the resource group name"
$vmName = "Enter VMSS Name"

$vmss = Get-AzVmss -ResourceGroupName $resourceGroup -VMScaleSetName $vmName
#Sku capacity is number of machines that will run once this script is executed
$vmss.sku.capacity = 5

Update-AzVmss -ResourceGroupName $resourceGroup -Name $vmName -VirtualMachineScaleSet $vmss

While using the above script for automating, you may need to login to the Azure using the poweshell itself using "Connect-AzAccount":

$azureAccountName ="Client Id"
$azurePassword = ConvertTo-SecureString "client_password" -AsPlainText -Force

$psCred = New-Object System.Management.Automation.PSCredential($azureAccountName, $azurePassword)

$tenantId="Enter Tenant id"

Connect-AzAccount -ServicePrincipal -Credential $psCred -Tenant $tenantId

This can be very useful when you need to scale up or down with using the Azure DevOps pipeline. Even the script can be effectively used in Azure Devops Powershell tasks.

No comments:

Post a Comment