Freigeben über


Azure PowerShell : Shutdown All Azure VMs

To Shutdown all Azure VM you don't need to go to individual and then press the button. But run an elegant PowerShell

 $AzureSubscriptions = Get-AzureSubscription
foreach ($subscription in $AzureSubscriptions)
{
    Write-Host $subscription.SubscriptionName

    Select-AzureSubscription -SubscriptionName $subscription.SubscriptionName
    #Write-Host $subscription.SubscriptionName
 
    foreach ($vm in Get-AzureVM)
    {
        $name = $vm.Name
        $servicename = $vm.ServiceName
    
        If($vm.Status -ne 'StoppedDeallocated')
        {
            # Add the VM's which should not be shutdown 
            
            Write-Host 'Stopping ' + $name
            Stop-AzureVM -Service $servicename -name $name
            
        }
        # do lots of other stuff
    }
}

Namoskar!!!

Comments

  • Anonymous
    June 21, 2015
    How to avoid pressing "yes" for each machine??

  • Anonymous
    July 06, 2015
    use -Force

  • Anonymous
    July 06, 2015
    To avoid pressing Yes, use Stop-AzureVM -Service $servicename -name $name -Force