How to safely replace Find-AzureRmResource -ResourceType calls in Azure PowerShell 6.x+

UPDATE: 2018-06-28 - Added resourcegroup ODataFilter example.

Starting with version 6.0 of Azure PowerShell, Find-AzureRmResource have been removed and Get-AzureRmResource is supposed to be the workaround.

My first reflex was to just convert Find-AzureRmResource -ResourceType to Get-AzureRmResource -ResourceType but I was unlucky and hit a regression and an error saying I could not only provide the ResourceType parameter.

On my machine, with version 5.2.0 of AzureRM.Resources module, I get the following error if trying the following command:

Get-AzureRmResource -ResourceType Microsoft.Storage/storageAccounts
Get-AzureRmResource : Parameter set cannot be resolved using the specified named parameters.
At line:1 char:1
+ Get-AzureRmResource -ResourceType Microsoft.Storage/storageAccounts
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-AzureRmResource], ParameterBindingException
    + FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
   .GetAzureResourceCmdlet

I found a safer way to replace a search by resource type, we can use the OData parameter like so:

Get-AzureRmResource -ODataQuery "`$filter=resourcetype eq 'Microsoft.Storage/storageAccounts'"

You can be more restrictive and filter by resource type & resource group :

Get-AzureRmResource -ODataQuery "`$filter=resourcetype eq 'Microsoft.Storage/storageAccounts' and resourcegroup eq 'myrg'"

This worked for me in AzureRM 5.x and AzureRM 6.x

Happy script rewrite!

Resources