FAQ: Find the resource group name for a resource with PowerShell

Find the resource group for a resource using PowerShell.

John Savill

April 29, 2016

1 Min Read
FAQ: Find the resource group name for a resource with PowerShell

Q. How can I easily find the resource group name for a resource using PowerShell in Azure?

A. Many times the AzureRM PowerShell commands require both the name and resource group of a resource to be actioned. It is actually fairly simple to find the resource group, in this example for a storage account but you can change the approach for any type of resource. In the PowerShell below all storage accounts are fed into a check for the required storage account then the resource group property is expanded.

$storAccount = 'savtechsalrsscus'$rgName = Get-AzureRmStorageAccount | where {$_.StorageAccountName -eq $storAccount} | Select-Object -ExpandProperty ResourceGroupName$storKey = (Get-AzureRmStorageAccountKey -Name $storAccount -ResourceGroupName $rgName ).Key1

 

About the Author

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like