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

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

 

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish