Search code examples
powershellazureazure-powershellservicebus

Get location value of Resource Group in a variable Powershell


I have a powershell script to deploy a service bus namespace

This is the command i use to deploy it .

New-AzureRmServiceBusNamespace -ResourceGroup $ResourceGroupName -NamespaceName $ServiceBusNamespace -Location $Location

The above command expects a location parameter to be entered. I want that location value as the Location where my resource group is located . How do i extract the Location value of my resource Group ?

I tried various methods and failed. it shows @{location=west us} , when i tried this

$location = Set-AzureRmResourceGroup -Name $ResourceGroupName -Tag @{} | Select-Object Location

Write-Host $location

Need help . Thanks !


Solution

  • $loc = Get-AzureRMResourceGroup -Name $ResourceGroupName | select-object -expandproperty location
    

    Well, if you want to GET something use appropriate verb. or like this:

    $rg = Get-AzureRMResourceGroup -Name $ResourceGroupName
    $rg.location