Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check If Azure Resource Group Exist - Azure Powershell

Tags:

I'm trying to verify if ResourceGroup exist or not so i thought that following code should return true or false, but it doesn't output anything.

$RSGtest = Find-AzureRmResource | Format-List ResourceGroupName | get-unique $RSGtest -Match "$myResourceGroupName" 

Why am I not getting any output?

like image 936
Peter Pavelka Avatar asked Jun 02 '16 17:06

Peter Pavelka


People also ask

What is the PowerShell command to get the Azure resource Group details?

The Get-AzResourceGroup cmdlet gets Azure resource groups in the current subscription. You can get all resource groups, or specify a resource group by name or by other properties. By default, this cmdlet gets all resource groups in the current subscription.

How do you identify a resource group in Azure?

Open resource groupsSign in to the Azure portal. Select Resource groups. Select the resource group you want to open.

Which Azure CLI command shows all resource groups?

To list the resource groups in your subscription, use az group list. To get one resource group, use az group show.

How do I make Azure resource Group in PowerShell?

The New-AzResourceGroup cmdlet creates an Azure resource group. You can create a resource group by using just a name and location, and then use the New-AzResource cmdlet to create resources to add to the resource group. To add a deployment to an existing resource group, use the New-AzResourceGroupDeployment cmdlet.


2 Answers

Update:

You should use the Get-AzResourceGroup cmdlet from the new cross-plattform AZ PowerShell Module now. :

Get-AzResourceGroup -Name $myResourceGroupName -ErrorVariable notPresent -ErrorAction SilentlyContinue  if ($notPresent) {     # ResourceGroup doesn't exist } else {     # ResourceGroup exist } 

Original Answer:

There is a Get-AzureRmResourceGroup cmdlet:

Get-AzureRmResourceGroup -Name $myResourceGroupName -ErrorVariable notPresent -ErrorAction SilentlyContinue  if ($notPresent) {     # ResourceGroup doesn't exist } else {     # ResourceGroup exist } 
like image 142
Martin Brandl Avatar answered Sep 26 '22 20:09

Martin Brandl


try this

$ResourceGroupName = Read-Host "Resource group name" Find-AzureRmResourceGroup | where {$_.name -EQ $ResourceGroupName} 
like image 28
Pawan Dubey Avatar answered Sep 25 '22 20:09

Pawan Dubey