gra*_*a36 4 powershell azure azure-powershell azure-automation
我想使用Get-AzureRm*Automation 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
Run Code Online (Sandbox Code Playgroud)
通过管理门户中的[测试]
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
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
因此,您需要做的是将适当的模块导入Azure自动化帐户。对于这些cmdlet- AzureRM.Websites。
由于需要提取每个活动,因此可能需要花费几分钟。
您将收到有关模块正在部署的通知以及完成后的通知。导入模块后,您将看到可用的活动,并且可以在运行手册和所需状态配置中使用其资源。
这是更多详细信息的链接:https : //docs.microsoft.com/zh-cn/azure/automation/automation-runbook-gallery#modules-in-powershell-gallery
| 归档时间: |
|
| 查看次数: |
1019 次 |
| 最近记录: |