Runbook中的Get-AzureRmAppServicePlan和Get-AzureRmWebApp返回异常 [英] Get-AzureRmAppServicePlan and Get-AzureRmWebApp return exceptions in Runbook

查看:83
本文介绍了Runbook中的Get-AzureRmAppServicePlan和Get-AzureRmWebApp返回异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Automation Runbook中的Get-AzureRm*命令获取所有属性,但是以下内容返回异常.如何编写代码以使这些命令正常工作?

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?

  • 返回异常
    • Get-AzureRmAppServicePlan
    • Get-AzureRmWebApp
    • Returns exception
      • Get-AzureRmAppServicePlan
      • Get-AzureRmWebApp
      • Get-AzureRmStorageAccount
      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
      

      [资产]-[模块]列表

      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 
      

      推荐答案

      因此,您需要做的是将适当的模块导入Azure自动化帐户.对于这些cmdlet- AzureRM.网站.

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

      1. 在Azure门户中,打开您的自动化帐户.
      2. 单击资产"磁贴以打开资产列表.
      3. 单击模块"磁贴以打开模块列表.
      4. 单击浏览图库"按钮,将启动浏览图库"刀片.
      5. 找到您感兴趣的模块,然后选择它以查看其详细信息. 深入研究特定模块时,可以查看有关该模块的更多信息,包括指向PowerShell库的链接,任何必需的依赖项以及该模块包含的所有cmdlet和/或DSC资源.
      6. 要将模块直接安装到Azure自动化中,请单击导入"按钮.
        单击导入"按钮时,您将看到要导入的模块名称.如果安装了所有依赖项,则确定"按钮将处于活动状态.如果缺少依赖项,则需要先导入依赖项,然后才能导入此模块.
      7. 单击确定"导入模块,然后将启动模块刀片.当Azure Automation将模块导入您的帐户时,它将提取有关模块和cmdlet的元数据.
      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://docs.microsoft.com/en-us/azure/automation/automation-runbook-gallery#modules-in-powershell-gallery

      这篇关于Runbook中的Get-AzureRmAppServicePlan和Get-AzureRmWebApp返回异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆