Getting the virtual machine ID ^
When it comes to managing virtual machines (VMs) in a VMSS, there are some important differences compared to traditional VM management. The first thing you need to be aware of is that there are separated PowerShell cmdlets that interact with VMs.
Secondly, in order to interact with VMs in a VMSS, you need to know the instance ID of the VM you want to manage.
To figure out the ID for the VMs, you can browse the resources.azure.com portal and extract your Resource Group -> VMSS.
Here, you can easily retrieve the VM ID. You can also get the same information from the Azure Portal Instances section:
Once you have the correct instance ID for a particular VM inside the VMSS, you can start using VMSS-related PowerShell commands. The following cmdlet helps you list the basic VM information:
Get-AzureRmVmssVM -ResourceGroupName VMSS -VMScaleSetName vmss01 -InstanceId 2
As mentioned previously, commands and outputs are different than with traditional Azure PowerShell cmdlets.
Starting and stopping VMs ^
Start and stop operations are also a bit different than with traditional VM implementations. As you may recall, for every single VMSS setup, you need to define a minimum instance count. This setting is quite important because by configuring a minimum instance count, you are forcing Azure to have a minimum X number of VMs available at all times, unless you stop them manually.
This is why Azure starts the minimum number of VMs you configured when you logged in to the Azure portal and started your VMSS instance.
You can start/stop/restart individual VMs or all VMs in a scale set by using PowerShell cmdlets:
Start/Stop/Restart all VMs in a scale set:
Start-AzureRmVmss -ResourceGroupName VMSS -VMScaleSetName vmss01
Stop-AzureRmVmss -ResourceGroupName VMSS -VMScaleSetName vmss01
Restart-AzureRmVmss -ResourceGroupName VMSS -VMScaleSetName vmss01
To Start/Stop/Restart an individual VM in a scale set:
Start-AzureRmVmss -ResourceGroupName VMSS -VMScaleSetName vmss01 -InstanceId 2
Stop-AzureRmVmss -ResourceGroupName VMSS -VMScaleSetName vmss01 -InstanceId 2
Restart-AzureRmVmss -ResourceGroupName VMSS -VMScaleSetName vmss01 -InstanceId 2
Changing the current capacity ^
You can also change the current capacity of your scale set manually without using auto-scale metrics. The following command gives you the current capacity details:
(Get-AzureRmVmss -ResourceGroupName vmss -VMScaleSetName VMSS01).sku
Using the .sku property, you can change the current count to 4:
$vmssConfig = Get-AzureRmVmss -ResourceGroupName vmss -VMScaleSetName VMSS01
$vmssConfig.sku.capacity = 4
Update-AzureRmVmss -ResourceGroupName vmss -Name VMSS01 -VirtualMachineScaleSet $vmssConfig
This will change the “Current number of instances” property to 4 and will fire up two additional VMs for my VMSS configuration.
In the next part, we will examine the availability and scalability options in Azure PaaS Services.