Freigeben über


PowerShell cmdlets to manage Azure Resource Manager (ARM) Virtual Machines

If you were looking for an easy way to programmatically manage your Azure Resource Manager (ARM) Virtual Machines within your Azure Subscription, this is definitely the right place.

The initial version of this script allows you to STOP/START/CHECK your ARM Virtual Machines within your Azure subscription, filtering by specific(s) Resource Group(s) or individual Virtual Machines if you wish. The first time you execute the script it will prompt for the subscription to use, by using 'Login-AzureRmAccount' cmdlet.

Pre-Requisites:

Azure Powershell should be installed and configured. See https://azure.microsoft.com/en-us/documentation/articles/powershell-install-configure/

If Azure Powershell is not configured as described, you will get following error when running the script:

  • Get-AzureRmVM : The term 'Get-AzureRmVM' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At C:\Scripts\psManageAzureRGVM.ps1:56 char:23 +         $AzureRGVMs = Get-AzureRmVM | foreach {$_.Name + "," + $_.Res ... +                       ~~~~~~~~~~~~~ + CategoryInfo          : ObjectNotFound: (Get-AzureRmVM:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

Parameters

  • Action (Mandatory)]: Specifies the action you want to execute: CHECK, STOP or START. No default value.
  • vmListToManage (Optional) : Specifies the list of ARM Virtual Machines you would like to manage. Empty value would mean all existing VM within your subscription. Default Value = Empty
  • resourceGroupListsToManage (Optional): Specifies the list of Resource Managers you would like to manage. Empty value would mean all exisiting Resource Group within your subscription. Default Value = Empty
  • forceRmAccountReload : Specifies whether you want to force Azure Rm Account reload. Default Value =False

Examples:

  • Check the status of all existing ARM Virtual Machines within your subscription.CheckVMStatus
  • Start specific ARM Virtual Machines. StartVMFilteringByVMNames
  • Stop ARM Virtual Machines belonging to specific Resource Group Names StopVMFilteringByRM

Download the code

You can download the code here, at MSDN Code Gallery.

 

Hope you find it interesting!