Azure Powershell命令用于获取资源组中的资源

时间:2016-05-05 05:43:01

标签: azure-powershell azure-resource-manager

在Azure Powershell版本0.8和0.9中,有命令

Get-AzureResource -ResourceGroupName "RGName" -OutputObjectFormat New

并且,它返回所提到的Azure资源组中的资源。它需要将azure模式设置为ARM模式。

但是,在Azure PowerShell 1.2及更高版本中

Get-AzureRMResource -ResourceGroupName "RGName" 

无法提供资源组中的资源。它需要诸如“ResourceID”或“ResourceName”之类的其他参数,这使得它具有资源特定性。

我需要的是,它应该返回资源组中的所有资源。 它是新版本的错误还是我错过了什么! 建议

4 个答案:

答案 0 :(得分:8)

您可以使用Find-AzureRmResource

Find-AzureRmResource -ResourceGroupNameContains "RGName"

答案 1 :(得分:4)

Get-AzureRMResource PowerShell命令是从REST API实现的。如果检查资源组中列出资源的REST API。你会看到这样的东西。

https://management.azure.com/subscriptions/<Subscription ID>/resourceGroups/<resource group name>/resources?api-version=2015-01-01

并且,如果您向-debug添加Get-AzureRMResource -ResourceId <the resource id>选项,您将找到它正在使用的REST API。

https://management.azure.com<the resource id>?api-version=2015-01-01

比较这两个REST API,您将看到以下PowerShell命令将列出资源组中的资源。

Get-AzureRmResource -ResourceId "/subscriptions/<Subscription ID>/resourceGroups/<resource group name>/resources"

我知道这很棘手,但确实有效。

答案 2 :(得分:2)

  

获取对象中的资源组

$groups = Get-AzureRmResourceGroup -Name $RG_Name 
  

获取变量

中资源组的所有资源
$t=(Find-AzureRmResource -ResourceGroupNameEquals 
$groups.ResourceGroupName).ResourceName

答案 3 :(得分:2)

尝试

Get-AzureRmResource | where {$_.ResourceGroupName -eq "RG"}