Runbook 中的 Get-AzureRmAppServicePlan 和 Get-AzureRmWebApp return 异常
Get-AzureRmAppServicePlan and Get-AzureRmWebApp return exceptions in Runbook
我想在 Automation Runbook 中使用 Get-AzureRm*
命令获取所有属性,但以下 return 例外。如何编码才能正确执行这些命令?
- Returns异常
- 获取 AzureRmAppServicePlan
- Get-AzureRmWebApp
- Returns 预期结果
- 获取 AzureRmStorageAccount
输入 - Powershell Runbook(不是工作流)
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
输出
通过管理门户中的[测试]
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.Websites.
使用 Azure 门户从自动化模块库导入模块
- 在 Azure 门户中,打开您的自动化帐户。
- 单击“资产”磁贴打开资产列表。
- 单击“模块”磁贴打开模块列表。
- 单击“浏览图库”按钮并启动“浏览图库”blade。
- 找到您感兴趣的模块并select它以查看其详细信息。
当您深入到特定模块时,您可以查看有关该模块的更多信息,包括 link 回到 PowerShell 库、任何必需的依赖项以及该模块包含的所有 cmdlet and/or DSC 资源.
- 要将模块直接安装到 Azure 自动化中,请单击“导入”按钮。
当您单击“导入”按钮时,您将看到要导入的模块名称。如果安装了所有依赖项,OK 按钮将处于活动状态。如果缺少依赖项,则需要先导入这些依赖项,然后才能导入此模块。
- 单击“确定”导入模块,模块blade 将启动。当 Azure 自动化将模块导入您的帐户时,它会提取有关模块和 cmdlet 的元数据。
这可能需要几分钟,因为每个 activity 都需要提取。
您将收到模块正在部署的通知以及部署完成时的通知。
模块导入后,您将看到可用的活动,您可以在您的运行手册和 Desired State Configuration 中使用它的资源。
这里有一个 link 以了解更多详情:https://docs.microsoft.com/en-us/azure/automation/automation-runbook-gallery#modules-in-powershell-gallery
我想在 Automation Runbook 中使用 Get-AzureRm*
命令获取所有属性,但以下 return 例外。如何编码才能正确执行这些命令?
- Returns异常
- 获取 AzureRmAppServicePlan
- Get-AzureRmWebApp
- Returns 预期结果
- 获取 AzureRmStorageAccount
输入 - Powershell Runbook(不是工作流)
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
输出
通过管理门户中的[测试]
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.Websites.
使用 Azure 门户从自动化模块库导入模块
- 在 Azure 门户中,打开您的自动化帐户。
- 单击“资产”磁贴打开资产列表。
- 单击“模块”磁贴打开模块列表。
- 单击“浏览图库”按钮并启动“浏览图库”blade。
- 找到您感兴趣的模块并select它以查看其详细信息。 当您深入到特定模块时,您可以查看有关该模块的更多信息,包括 link 回到 PowerShell 库、任何必需的依赖项以及该模块包含的所有 cmdlet and/or DSC 资源.
- 要将模块直接安装到 Azure 自动化中,请单击“导入”按钮。
当您单击“导入”按钮时,您将看到要导入的模块名称。如果安装了所有依赖项,OK 按钮将处于活动状态。如果缺少依赖项,则需要先导入这些依赖项,然后才能导入此模块。 - 单击“确定”导入模块,模块blade 将启动。当 Azure 自动化将模块导入您的帐户时,它会提取有关模块和 cmdlet 的元数据。
这可能需要几分钟,因为每个 activity 都需要提取。
您将收到模块正在部署的通知以及部署完成时的通知。 模块导入后,您将看到可用的活动,您可以在您的运行手册和 Desired State Configuration 中使用它的资源。
这里有一个 link 以了解更多详情:https://docs.microsoft.com/en-us/azure/automation/automation-runbook-gallery#modules-in-powershell-gallery