You will need to change a few things in these scripts to suit your purposes:
- Change "YourAzureAccount@hotmail.com" to your Azure account. For MSDN-based Azure subscriptions like mine, this address was my Hotmail email address.
- Change "Visual Studio Premium with MSDN" to the name of your Azure Subscription. This was the name my MSDN-based account was given by default.
- Populate the $vms variable with a list of Azure VM's in the cluster you're looking to start/stop as a group, replacing "yourVMName-alwayson-dom" and so forth.
Stop a list of Azure Accounts:
Note about the -StayProvisioned tag above. Specifying this option will retain some IP settings, but will cause your VM's to continue to accrue Azure credit, even while stopped. Use with care.#if expired, Add-AzureAccount Get-AzureSubscription | ? {$_.ActiveDirectoryUserId -eq 'YourAzureAccount@hotmail.com' -and $_.SubscriptionName -match "Visual Studio Premium with MSDN" } | Set-AzureSubscription -SubscriptionId $_.SubscriptionID $vmHash =@{} $vms = "yourVMName-alwayson-dom","yourVMName-alwaysonsql1","yourVMName-alwaysonsql2","yourVMName-alwaysonWSFC" Get-AzureVM | foreach{$vmHash.Add($_.Name,$_.ServiceName)} foreach ($vm in $vms) { $currentVMService = $vmHash[$vm] Write-Host "Current VM:$($vm)" $thisvm = Get-AzureVM -ServiceName $currentVMService -Name $vm Write-Host "Stopping VM:$($thisvm.Name)" Stop-AzureVM -Name $thisvm.Name -ServiceName $thisvm.ServiceName #-StayProvisioned }
Start a list of Azure Accounts:
#if expired, Add-AzureAccount Get-AzureSubscription | ?{$_.ActiveDirectoryUserId -eq 'YourAzureAccount@hotmail.com' -and $_.SubscriptionName -match "Visual Studio Premium with MSDN" } | Set-AzureSubscription -SubscriptionId $_.SubscriptionID $vmHash =@{} $vms = "yourVMName-alwayson-dom","yourVMName-alwaysonsql1","yourVMName-alwaysonsql2","yourVMName-alwaysonWSFC" Get-AzureVM | foreach{$vmHash.Add($_.Name,$_.ServiceName)} foreach ($vm in $vms) { $currentVMService = $vmHash[$vm] Write-Host "Current VM:$($vm)" $thisvm = Get-AzureVM -ServiceName $currentVMService -Name $vm Write-Host "Starting VM:$($thisvm.Name)" Start-AzureVM -Name $thisvm.Name -ServiceName $thisvm.ServiceName }
If upon running the scripts you receive either of these errors:
get-azuresubscription : The term 'get-azuresubscription' is not recognized as the name of a cmdlet,
Get-AzureVM : The term 'Get-AzureVM' is not recognized as the name of a cmdlet, function, script file, or
Then you don't have the PowerShell module loaded, and PowerShell isn't automatically loading it for you. Use the Import-Module command. Below is the default location of the module, downloaded from here: https://azure.microsoft.com/en-us/documentation/articles/powershell-install-configure/
Import-Module 'C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Azure.psd1'
Updated 20160322 to reflect the latest module paths