locked
Resource Manager Cmdlets RRS feed

  • Question

  • I'm trying to create a basic runbook that enumerates my resource groups.

    The PowerShell part itself is very easy:

    workflow Wipe-Subscription {
        
        param (        
            [parameter(Mandatory=$true)]
            [String]
            $Subscription = "[default subscription name]"
        )
        
        $Cred = Get-AutomationPSCredential -Name "[user]@[directory].onmicrosoft.com"
        
        $null = Add-AzureAccount -Credential $Cred
        
        $null = Select-AzureSubscription -SubscriptionName $Subscription
        
        Switch-AzureMode AzureResourceManager
    
        Get-AzureResourceGroup
            
    }

    For some reason, it fails when I call Switch-AzureMode and therefore the corresponding Cmdlets are not available.  Any idea if I am doing anything wrong?


    • Edited by Sidney_Andrews Friday, October 31, 2014 7:14 PM Forgot code block
    Friday, October 31, 2014 7:13 PM

Answers

  • Hi Sidney,

    We do not ship the Azure Resource Manager module out of the box yet in Azure Automation like we do the Azure (AzureServiceManagement) module. We have done some limited testing on the ARM module in Azure Automation. If you would like to import this module yourself, here are the steps to get ARM set up in Azure Automation:

    Step 1 – Create an Azure Automation Integration Module from the AzureResourceManager PowerShell module.

    Navigate to the AzureResourceManager module within the Azure PowerShell directory on a host with Azure PowerShell installed.

    Zip up the AzureResourceManager folder.

    Step 2 – Import into Azure Automation

    Importing this zip as an integration module into Azure Automation works fine as the below screenshots show:

    Step 3 – Write a Runbook that uses AzureResourceManager functionality

    Like you normally would, except no need to use Switch-AzureMode to switch between AzureServiceManagement and AzureResourceManager, as both AzureServiceManagement and AzureResourceManager modules are now in the PS path.


    • Edited by Joe Levy_ Wednesday, November 5, 2014 1:36 AM
    • Proposed as answer by Joe Levy_ Wednesday, November 5, 2014 1:38 AM
    • Marked as answer by Sidney_Andrews Wednesday, November 5, 2014 2:53 PM
    Wednesday, November 5, 2014 1:35 AM

All replies

  • Hi Sidney,

    We do not ship the Azure Resource Manager module out of the box yet in Azure Automation like we do the Azure (AzureServiceManagement) module. We have done some limited testing on the ARM module in Azure Automation. If you would like to import this module yourself, here are the steps to get ARM set up in Azure Automation:

    Step 1 – Create an Azure Automation Integration Module from the AzureResourceManager PowerShell module.

    Navigate to the AzureResourceManager module within the Azure PowerShell directory on a host with Azure PowerShell installed.

    Zip up the AzureResourceManager folder.

    Step 2 – Import into Azure Automation

    Importing this zip as an integration module into Azure Automation works fine as the below screenshots show:

    Step 3 – Write a Runbook that uses AzureResourceManager functionality

    Like you normally would, except no need to use Switch-AzureMode to switch between AzureServiceManagement and AzureResourceManager, as both AzureServiceManagement and AzureResourceManager modules are now in the PS path.


    • Edited by Joe Levy_ Wednesday, November 5, 2014 1:36 AM
    • Proposed as answer by Joe Levy_ Wednesday, November 5, 2014 1:38 AM
    • Marked as answer by Sidney_Andrews Wednesday, November 5, 2014 2:53 PM
    Wednesday, November 5, 2014 1:35 AM
  • This was it!  I am now importing a lot of my favorite PowerShell modules into Azure Automation.  Thanks!
    Wednesday, November 5, 2014 2:53 PM
  • This no longer works with the current azure resource manager.

    The module is larger than the 30 MB limit.

    i managed to remove modules i do not use to be under the 30 MB limit but now i'm getting a type init error on all my commands...

    Wednesday, May 6, 2015 6:42 PM
  • We are upping the module import size limit through the portal to 40 MB in the next couple weeks.

    You can use the New-AzureAutomationModule cmdlet as well, which does not have a size limit.

    Monday, May 11, 2015 10:32 PM
  • Hey Joe, 

    I imported the ARM module as you described, but am seeing an error now when trying to use the service management cmdlets (the ARM cmdlets work fine). Is using Switch-AzureMode not supported in this case, or is there something akin to this that is needed? In this case I'm running the ARM stuff before the "regular" stuff. The cmdlet in this case is Get-AzureVM with no parameters, inside an InlineScript block.

    Here is the error (doing Import-Module after the second error told me to for more info):

    Import-Module : C:\Modules\User\AzureResourceManager\Resources\ServiceManagementStartup.ps1
    At Assert-AutoShutdownSchedule:62 char:62
    + 
        + CategoryInfo          : NotSpecified: (:) [Import-Module], FileNotFoundException
        + FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.ImportModuleCommand
     
    Get-AzureVM : The 'Get-AzureVM' command was found in the module 'Azure', but the module could not be loaded. For more 
    information, run 'Import-Module Azure'.
    At Assert-AutoShutdownSchedule:62 char:62
    + 
        + CategoryInfo          : ObjectNotFound: (Get-AzureVM:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule
    



    Automys | Downloadable Microsoft automation examples and solutions

    Monday, May 18, 2015 8:11 PM
  • switch-azuremode is not supported, you do not need to use it.

    as far as i have been able to test, the resource manager does not seem to work with automation currently. Throws plenty of errors. I will try to use with a subscription without the std azure module to let you know if it works.

    Modules are loaded by the automation backend and not by the user so importing modules using powershell is not a solution nor supported.

    regards,

    Gabriel Gosselin

    Monday, May 18, 2015 8:24 PM
  • Hi Noah,

    Switch-AzureMode is not needed because the two modules (Azure and AzureResourceManager) are loaded side by side in Azure Automation, instead of switching which one is loaded using Switch-AzureMode. In addition, Import-Module is not needed because any module imported into Azure Automation is automatically placed into the PSPath, so these modules are already loaded.

    Please try again without using Switch-AzureMode and Import-Module. Since the Azure and AzureResourceManager modules both have Get-AzureVM in the path, you may need to prefix the cmdlet with the module name to disambiguate. Ex: AzureResourceManager\Get-AzureVM or Azure\Get-AzureVM.

    Please also make sure that the Azure and AzureResourceManager modules are the same version #, in your Azure Automation account.

    Tuesday, May 19, 2015 1:36 AM
  • Thanks for clarifying, that is helpful. Can you point me to where I find the module versions in the automation account? I see an integer number, "18", but I assume I need to match the actual PS module version a la 0.8.x?

    Automys | Downloadable Microsoft automation examples and solutions

    Tuesday, May 19, 2015 1:43 AM
  • I assume you're looking at the new preview portal. I think right now this information is only available in the old portal. Can you look there or use the Azure / ARM Get-AzureAutomationModule cmdlets to find this?
    Tuesday, May 19, 2015 1:53 AM
  • Yes, thanks Joe. Module versions are correctly shown in the old portal, not the new. I found my Azure module to be 0.8.16, and I was only able to get my runbook to work by uploading the Azure Resource Manager zipped module as described above, of same version, plus the file "ServiceManagementStartup.ps1" copied from the ServiceManagement Compute subfolder into the ARM "Resources" subfolder. Without including this additional file, I get the FileNotFoundException shown in my previous post.

    So, this combo works for me:

    - Azure module 0.8.16 in Automation Account

    - Azure Resource Manager module 0.8.16 including Resources\ServiceManagementStartup.ps1 (attempt with 0.9.1 did not work)

    This seems pretty hackish, so I'm interested in any better ways I may be missing.


    Automys | Downloadable Microsoft automation examples and solutions

    Tuesday, May 19, 2015 2:59 AM
  • FYI - I've created a step-by-step article on how to enable the Azure RM commandlets. If you try to use the GUI (as Joe highlights above) you might get hit with the file size is too big until this UX limit is lifted.

    http://www.itproguy.com/how-enable-azure-rm-commandlets-in-azure-automation/

    Thursday, May 21, 2015 6:31 PM
  • Thanks David. It seems the size limit is raised in the portal based on a successful upload of the latest 0.9.1 version of the module, which is over 30MB.

    I also covered the uploaded procedure along with an example that uses the ARM module for runbook power scheduling. It also provides in the download a modified copy of the 0.8.16 module that contains the file ServiceManagementStartup.ps1 that I found was needed to work around an exception.


    Automys | Downloadable Microsoft automation examples and solutions

    Thursday, May 21, 2015 6:48 PM