【问题标题】:Azure runbook GetMember ErrorAzure Runbook GetMember 错误
【发布时间】:2016-03-03 02:38:19
【问题描述】:

我有以下运行手册脚本,它应该将应用程序设置从一个 Web 应用程序复制到另一个,但是当我运行它时出现错误。

# Get the credential to use for Authentication to Azure and Azure Subscription Name
$cred = Get-AutomationPSCredential -Name 'Credintial'
Login-AzureRmAccount -Credential $cred

$fromResourceGroup = 'parkprod'
$fromSite = 'parkprod'
$toResourceGroup = 'cmsfarhad'
$toSite = 'farhadparkingapi'

$props = (Invoke-AzureRmResourceAction -ResourceGroupName $fromResourceGroup -ResourceType Microsoft.Web/sites/Config -Name $fromSite/appsettings -Action list -ApiVersion 2015-08-01 -Force).Properties

$hash = @{}
$props | Get-Member -MemberType NoteProperty | % { $hash[$_.Name] = $props.($_.Name) }

Set-AzureRMWebApp -ResourceGroupName $toResourceGroup -Name $toSite -AppSettings $hash

错误:

Environments                                                                                           Context          
------------                                                                                           -------          
{[AzureCloud, AzureCloud], [AzureChinaCloud, AzureChinaCloud], [AzureUSGovernment, AzureUSGovernment]} Microsoft.Azur...
Invoke-AzureRmResourceAction : Object reference not set to an instance of an object.
At line:10 char:11
+ $props = (Invoke-AzureRmResourceAction -ResourceGroupName $fromResour ...
+           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], NullReferenceException
    + FullyQualifiedErrorId : System.NullReferenceException

Get-Member : The input object cannot be bound to any parameters for the command either because the command does not 
take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.
At line:13 char:10
+ $props | Get-Member -InputObject $f -MemberType NoteProperty | % { $h ...
+          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-Member], ParameterBindingException
    + FullyQualifiedErrorId : InputObjectNotBound,Microsoft.PowerShell.Commands.GetMemberCommand

Get-Member : You must specify an object for the Get-Member cmdlet.
At line:13 char:10
+ $props | Get-Member -InputObject $f -MemberType NoteProperty | % { $h ...
+          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Get-Member], InvalidOperationException
    + FullyQualifiedErrorId : NoObjectInGetMember,Microsoft.PowerShell.Commands.GetMemberCommand

Set-AzureRMWebApp : The term 'Set-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 line:15 char:1
+ Set-AzureRMWebApp -ResourceGroupName $toResourceGroup -Name $toSite - ...
+ ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Set-AzureRMWebApp:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

【问题讨论】:

    标签: powershell azure azure-powershell azure-automation


    【解决方案1】:

    你必须安装AzureRm.Websites。缺少该模块的 cmdlet。检查您的系统上是否安装了它,如果没有安装它。

    【讨论】:

    • 我不确定你的意思,因为这是一个运行手册脚本,我是否还需要安装那个 cmdlet ,或者它不是已经包含在其中了吗?
    【解决方案2】:

    正如 Peter 所说,AzureRM.Websites PowerShell 模块当前未在自动化服务中提供,因此您需要自己导入此模块。有关详细信息,请参阅https://azure.microsoft.com/en-us/blog/announcing-azure-resource-manager-support-azure-automation-runbooks/

    但您在使用 Invoke-AzureRmResourceAction cmdlet 时似乎也存在问题。返回的错误不是很有用,而且我对那个 cmdlet 不是很熟悉,所以我很难说出你做错了什么。要测试的一件事是检查相同的 cmdlet 调用是否在本地 PowerShell 中有效。如果它在本地 PowerShell 中不起作用,则问题出在您的代码上,而不是 Azure 自动化中的任何怪癖。

    【讨论】:

      猜你喜欢
      • 2020-03-01
      • 2018-03-02
      • 1970-01-01
      • 2017-11-07
      • 1970-01-01
      • 1970-01-01
      • 2019-07-03
      • 2019-05-17
      • 2019-07-28
      相关资源
      最近更新 更多