2
votes

In the Azure Powershell version 0.8 and 0.9, there is command

Get-AzureResource -ResourceGroupName "RGName" -OutputObjectFormat New

And, It returns the resources in the mentioned Resource Group of Azure. It necessitates the azure mode to be ARM mode.

But, in the Azure PowerShell version 1.2 and above

Get-AzureRMResource -ResourceGroupName "RGName" 

fails to provide the resources present in a Resource Group. It needs further parameters like "ResourceID" or "ResourceName" which makes it resource specific.

What I need is that, it should return all the resources in a resource group. Is it a bug with the newer version or am I missing something! Suggest

4

4 Answers

8
votes

You can use Find-AzureRmResource:

Find-AzureRmResource -ResourceGroupNameContains "RGName"
4
votes

The Get-AzureRMResource PowerShell Command is implemented from REST API. If you check the REST API of listing resources in a resource group. You will see something like this.

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

And, if you add -debug option to Get-AzureRMResource -ResourceId <the resource id>, you will find the REST API it's using.

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

Comparing this two REST API, you will see that the following PowerShell command will list the resources in a resource group.

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

I know it's tricky, but it does work.

4
votes

Try

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

Get the resource group in an object

$groups = Get-AzureRmResourceGroup -Name $RG_Name 

fetch all the resources of a resource group in a variable

$t=(Find-AzureRmResource -ResourceGroupNameEquals 
$groups.ResourceGroupName).ResourceName