0

I have created some Azure VMs using the new Resource Manager and i'd like to stop them everyday.

To do so, i've published a runbook to stop aboth classic and ARM VMs, and i created a scheduler which runs the runbook every night :

workflow Stop-AzureVMs { $cred = Get-AutomationPSCredential -Name 'Cred' Add-AzureAccount -Credential $cred Select-AzureSubscription -Current 'SubscriptionName' Get-AzureVM | Stop-AzureVM –Force Get-AzureRmVM | Stop-AzureRmVM -Force } 

I have imported the AzureResourceManager module to my Azure Automation account :

Azure Automation Modules

But i am getting this error :

Exception At line:34 char:2 + Get-AzureRMVM | Stop-AzureRMVM -Force + ~~~~~~~~~~~~~ Cannot find the 'Get-AzureRMVM' command. If this command is defined as a workflow, ensure it is defined before the workflow that calls it. If it is a command intended to run directly within Windows PowerShell (or is not available on this system), place it in an InlineScript: 'InlineScript { Get-AzureRMVM }' 

How is that possible ?

Edit : Below is the solution

 $cred = Get-AutomationPSCredential -Name 'Cred' Add-AzureRmAccount -Credential $cred Select-AzureRmSubscription -Name 'SubscriptionName' -SubscipritionId 'SubscriptionId' Get-AzureRmVM | Stop-AzureRmVM -Force 

All workflows i found didn't mention the use of Add-AzureRmAccount and Select-AzureRmSubcription instead of the standard Add-AzureAccount and Select-AzureSubscription. I thought that the authentication process to our Azure account was the same.

Update : It is now possible to combine both ASM and ARM cmdlets within the same runbooks, see this post for more informations about ARM supported by default on Azure Automation

2
  • may I know what exactly you are trying to achive using command- Get-AzureRMVM I googled this command but couldn't get anything Commented Oct 25, 2015 at 19:02
  • Just trying to get my ARM VMs. Commented Oct 25, 2015 at 20:19

7 Answers 7

1

Looks like you imported the old version of the ARM cmdlets (before Azure PS 1.0) into Azure Automation. This was before the *-AzureRm* renaming. So tt should be Stop-AzureVM not Stop-AzureRmVM.

However, that makes it ambiguous as to whether you are trying to call Azure Service Management or Azure Resource Manager cmdlets -- which is exactly why the cmdlet names were renamed in Azure PS 1.0. I recommend you follow the guidance here.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi Joe, thank you for your reply. I tried to get this work by reading your article :) I succeed after a lot of disapointemens.I was confusing some ARM and ASM cmdlets. Now i now that we need to Add-AzureRmAccount, Select-AzureRmSubcription etc ... I've updated my question with the solution.
0

As per my understanding ASM mode is default. If you are going for ARM command firstly switch mode is required using Switch-AzureMode

One more confusion is what is the purpose of Get-AzureRMVM command. I googled but coulndn't find anything -

enter image description here

3 Comments

There is two VMs creation mode in Azure preview portal : ASM (classic) and ARM (new). To get ARM VMs i have to use the Get-AzureRmVM cmdlet just like i will use Get-AzureVM to get ASM VMs. With the new version of ARM module (0.10.0), you don't have to switch to use ARM cmdlets.
I got it. Well in that case here is the link which can help you - blog.kloud.com.au/2015/03/24/… I would request you to go through entire blog
Thanks but i'm using the version 0.9.1 of Azure PowerShell module and version 0.10.0 of Azure Resource Manager PowerShell module, so this link is outdated (don't have to use Switch cmldet to use the ARM cmdlets in version 0.10.0).
0

The Get-AzureRMVM cmdlet is in the AzureRM.Compute module... The AzureRM* cmdlets are still in preview, I don't think they are available in Azure Automation yet.

The two modules in your screenshot above likely correspond to the 0.9.x version of the cmdlets and there were indeed two different modules (Azure=ASM and AzureResourceManager=ARM) behind Switch-AzureMode. Switch-AzureMode just unloads one and loads the other.

If Automation is still using the 0.9.x version of the cmdlets then you should be able to just use Get-AzureVM for ARM VMs using the AzureResourceManager module.

Comments

0

Below is the solution

$cred = Get-AutomationPSCredential -Name 'Cred' Add-AzureRmAccount -Credential $cred Select-AzureRmSubscription -Name 'SubscriptionName' -SubscriptionId 'SubscriptionId' Get-AzureRmVM | Stop-AzureRmVM -Force 

It is not yet possible to combine ARM and ASM cmdlets in same runbook apparently ... So you have to use only ARM cmdlet or ASM cmdlet.

Also, all workflows i found didn't mention the use of Add-AzureRmAccount and Select-AzureRmSubcription instead of the standard Add-AzureAccount and Select-AzureSubscription.

I thought that the authentication process to our Azure account was the same.

2 Comments

FYI the ARM and ASM cmdlets can now be used side by side in Azure Automation. Please see azure.microsoft.com/en-us/blog/…
Yep, i saw your post on azure blog last week :) Already implemented it on my Azure Automation account and it works well !
0

The Following code will work for both old style and new Style VM's but be aware this will shut down all machines with no warning.

{ # TODO: update to the name of the credential asset in your Automation account $AutomationCredentialAssetName = "AzureAutomationRG" # Get the credential asset with access to my Azure subscription $Cred = Get-AutomationPSCredential -Name $AutomationCredentialAssetName # Authenticate to Azure Service Management and Azure Resource Manager Add-AzureAccount -Credential $Cred Add-AzureRmAccount -Credential $Cred "`n-Old Style VMS-`n" # Get and output Azure classic VMs $VMs = Get-AzureVM $VMs.Name Get-AzureVM | Stop-AzureVM -Force "`n-New Style Resource Group VMs-`n" # Get and output Azure v2 VMs $VMsv2 = Get-AzureRmVM $VMsv2.Name Get-AzureRmVM | Stop-AzureRmVM -Force } 

Comments

0

For new Azure RM VMs use access extensions the following command:

Set-AzureRmVMAccessExtension -ResourceGroupName "ResourceGroupName" -VMName "VMName" -Username "Admin User Name" -Password "Admin Password" -Name "Extension Name" 

Please note the -Name parameter is the arbitrary extension name.

Comments

0

This might be late to the party, but I would recommend you check out this link:

https://www.attosol.com/start-or-stop-all-vms-of-a-resource-group-in-azure/

Basically, you can create a script and write some aliases with switches to make your job super easy.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.