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?
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.
Open resource groupsSign in to the Azure portal. Select Resource groups. Select the resource group you want to open.
To list the resource groups in your subscription, use az group list. To get one resource group, use az group show.
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.
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 }
try this
$ResourceGroupName = Read-Host "Resource group name" Find-AzureRmResourceGroup | where {$_.name -EQ $ResourceGroupName}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With