Restart Azure VM/a list of VMs/All VMs,VMSS/Service Fabric Nodes


This PowerShell Workflow runbook connects to Azure using an Automation Credential and Starts/Stops a VM/a list of VMs/All VMs in a Subscription in-parallel. You can attach a recurring schedule to this runbook to run it at a specific time.REQUIRED1. SubscriptionName- pa


1. SubscriptionName- parameter that allows scoping Nodes to a particular Subscription.

2. ResourceGroupName- parameter to input the Resource Group which containes the Nodes

3. NodeToRestart –  parameter to input the Node name to Restart

4. Region – Optional parameter to choose Region (NA/China/Government)


1. AzureCredential – Is added as an credential under Shared Resources at the Automation Account level. This is used to Login to Azure using Login-AzureRmAccount


$NodeToRestart, # Primary Node Should not be rebooted

if($Region -eq “NA”)
$credential = Get-AutomationPSCredential -Name ‘AzureCredential’
Login-AzureRmAccount -Credential $credential
$credential = Get-AutomationPSCredential -Name ‘AzureCNCredential’
Login-AzureRmAccount -EnvironmentName AzureChinaCloud -Credential $credential

Select-AzureRmSubscription -SubscriptionName $SubscriptionName

$VMSSInstances = (Get-AzureRmVmssVM -ResourceGroupName $ResourceGroupName -VMScaleSetName $NodeToRestart).InstanceId
foreach ($VMSSInstance in $VMSSInstances)
Write-Output ” Restarting instance [$VMSSInstance] in VMSS: [$NodeToRestart]”
Restart-AzureRmVmss -ResourceGroupName $ResourceGroupName -VMScaleSetName $NodeToRestart -InstanceId $VMSSInstance -Verbose -ErrorAction Stop
Sleep -Seconds 10

Be the first to comment

Leave a Reply

Your email address will not be published.