2

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

5 Answers 5

8

You can use Find-AzureRmResource:

Find-AzureRmResource -ResourceGroupNameContains "RGName"
Sign up to request clarification or add additional context in comments.

2 Comments

But, it comes with a warning, saying "tagvalue" will get modified in future release. I hope this command should work in future as well. Thanks
I believe that warning is due to the fact that Find-AzureRmResource has TagName and TagValue parameters, but Find-AzureRmResourceGroup has a Tag parameter. They will be changing these cmdlets to work the same way. If you're not searching by tag then your scripts will not be impacted if and when this is changed.
4

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.

Comments

4

Try

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

2 Comments

Tried to write ODataQuery but then your answer simplified the problem a great deal: Get-AzureRmResource -ODataQuery "`$filter=resourcetype eq 'Microsoft.Storage/storageAccounts'" | where { $_.ResourceName.StartsWith('myappblobstorage') -and $_.ResourceGroupName -eq '$ResourceGroupNameBlob' }
"$ResourceGroupNameBlob" (for variable)
3

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

Comments

0

You can use a very simple command Get-AzResource -ResourceGroupName $rg to get all the resources within a Resource Group and then can loop through to perform some task.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.