top of page
Writer's pictureRattandeep singh

#Powershell, #Azure, and #ResourceGroups.



Hey there, I'm back again with a new post to use PowerShell. However, this time I will use it in Azure.


In this post, I will demonstrate:

  • Creation of some test Resource Groups

  • Get the Resource Groups using the Region

  • Get the Resource Groups using the Tags assigned

  • Delete Resource Groups using Tag values

Let's start by connecting to the #Azure #PowerShell in a web Browser.

Open URL Portal.Azure.Com. It will take show the page with a credential promp to enter the username and password.


After the login is complete, the home page for Azure account will be displayed. In which you need to click the "Cloud Shell" icon on the top right.

The Blue Cloud Shell window should open like in the below screen shot.

Now let's start by checking, if I have any Resource Groups available.

I have used the command to check resource groups in a specific region "WestUS". There is no output stating there are no Resource Groups Available.







Creation of some test Resource Groups

Let's now create certain resource groups in the same region "West US" by using the below command.

for($i=0;$i -le 2;$i++){New-AzResourceGroup "DesignbotsRGWUS$i" -Location WestUS -Tag @{Name ="BusinessUnit"; Value = "Finance"} -Force }

I have used the command with the "for" loop to allow me create multiple Resource Groups at the same time, in the same Region, and assigning the same Tags. As the for loop ran 3 times, I have 3 new Resource Groups Created. The output on the screen looks like below.






























Get the Resource Groups using the Region

It is time to find the Resource Groups in a Region. Below I have used the command to get the Resource Groups base on the location/Region and also selected few attributes to make the output a little smaller.






















Get the Resource Groups using the Tags assigned

First I stored the Tag name and the value in variable $tname and $tvalue. Then used those in the command Get-AzResourceGroup -Tag @{$tname = $tvalue}

It display all the Resource Groups with the Tag [BusinessUnit,Finance] from my Azure subscription.































Delete Resource Groups using Tag values

It is time to Delete all the resource groups with the Tag [BusinessUnit,Finance] at once.

I used the command shared below. It will take some time but will delete all Resource Groups with the Tag [BusinessUnit,Finance].

Output on the screen as True shows the delete operation success.

Get-AzResourceGroup -Tag @{$tname = $tvalue} | Remove-AzResourceGroup -Force




137 views0 comments

コメント


bottom of page