Get-AzureRmAppServicePlan and Get-AzureRmWebApp return exceptions in Runbook

1.4k views Asked by At

I'd like to get all properties with Get-AzureRm* commands in Automation Runbook, but the followings return exception. How to code so as to work these commands properly?

  • Returns exception
    • Get-AzureRmAppServicePlan
    • Get-AzureRmWebApp
  • Returns expected result
    • Get-AzureRmStorageAccount

input - Powershell Runbook (not Workflow)

Write-Output $PSVersionTable
$resourceGroupName = "(snipped)"
$appServicePlans = Get-AzureRmAppServicePlan -ResourceGroupName $resourceGroupName

$Cred = Get-AutomationPSCredential -Name "pscred" # works as expected
Add-AzureRmAccount -Credential $Cred
Add-AzureAccount -Credential $Cred

$appServicePlans = `
    Get-AzureRmAppServicePlan -ResourceGroupName $resourceGroupName
$appServices = `
    Get-AzureRmWebApp -ResourceGroupName $resourceGroupName
$storageAccounts = `
    Get-AzureRmStorageAccount -ResourceGroupName $resourceGroupName

output

By [Test] in Management Portal

Name                           Value
----                           -----
PSVersion                      5.0.10514.2
WSManStackVersion              3.0
SerializationVersion           1.1.0.1
CLRVersion                     4.0.30319.19455
BuildVersion                   10.0.10514.2
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3

Get-AzureRmAppServicePlan : The term 'Get-AzureRmAppServicePlan' 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 (position in the source)
+ $appServicePlans = Get-AzureRmAppServicePlan -ResourceGroupName $reso ...
+                    ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (Get-AzureRmAppServicePlan:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

Get-AzureRmWebApp : The term 'Get-AzureRmWebApp' 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 (position in the source)
+ $appServices = Get-AzureRmWebApp -ResourceGroupName $resourceGroupNam ...
+                ~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (Get-AzureRmWebApp:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

# $storageAccounts has got as expected

[Asset] - [Module] list

Azure
Azure.Storage 
AzureRM.Automation 
AzureRM.Compute 
AzureRM.Profile 
AzureRM.Resources 
AzureRM.Sql 
AzureRM.Storage 
Microsoft.PowerShell.Core 
Microsoft.PowerShell.Diagnostics 
Microsoft.PowerShell.Management 
Microsoft.PowerShell.Security 
Microsoft.PowerShell.Utility 
Microsoft.WSMan.Management 
Orchestrator.AssetManagement.Cmdlets 
1

There are 1 answers

1
4c74356b41 On BEST ANSWER

So what you need to do is import the appropriate module(s) into you Azure Automation Account. For these cmdlets - AzureRM.Websites.

To import a module from the Automation Module Gallery with the Azure portal

  1. In the Azure Portal, open your Automation account.
  2. Click on the Assets tile to open the list of assets.
  3. Click on the Modules tile to open the list of modules.
  4. Click on the Browse gallery button and the Browse gallery blade is launched.
  5. Locate a module that you're interested in and select it to view its details. When you drill into a specific module, you can view more information about the module, including a link back to the PowerShell Gallery, any required dependencies, and all of the cmdlets and/or DSC resources that the module contains.
  6. To install the module directly into Azure Automation, click the Import button.
    When you click the Import button, you will see the module name that you are about to import. If all the dependencies are installed, the OK button will be active. If you are missing dependencies, you need to import those before you can import this module.
  7. Click OK to import the module, and the module blade will launch. When Azure Automation imports a module to your account, it extracts metadata about the module and the cmdlets.

This may take a couple of minutes since each activity needs to be extracted.

You will receive a notification that the module is being deployed and a notification when it has completed. After the module is imported, you will see the available activities, and you can use its resources in your runbooks and Desired State Configuration.

Here's a link for more details: https://learn.microsoft.com/en-us/azure/automation/automation-runbook-gallery#modules-in-powershell-gallery