Preparing AZ-104 : Creating Resource group from PowerShell and related CMDLETs – Azure Administration

fig : AZURE – removing resource group from current subscription
fig : AZURE – removing resource group from current subscription

Hi All,

Greetings for the day!!!

In this article we will discuss how to create Resource group using PowerShell

We have detailed article to start with AZURE PowerShell if you are new to AZURE PowerShell. Please have a look – Configure PowerShell For Microsoft Azure Az Module AND Azure PowerShell – Knowing the basics and starting with few important CMDLETS

What is Resource Group

  • If you are new to AZURE and dont know about Resource Groups, we have a very good article. Kindly please have a look – Azure – Resource and Resource group
  • Resource Group is container for related AZURE resources
  • Resource Group stores metadata about resources
  • Location of resource group determines where the metadata of resources will be stored

    POWERSHELL CMDLET to create resource group

    • Currently there is only one resource group – “rg-azure-dev-centralindia-001” in my environment as
    fig : Azure - Resource group listing
    fig : Azure – Resource group listing
    • PowerShell CMDLET for creating new resource group is – New-AzResourceGroup
    • Syntax
    New-AzResourceGroup
       [-Name] <String>
       [-Location] <String>
       [-Tag <Hashtable>]
       [-Force]
       [-ApiVersion <String>]
       [-Pre]
       [-DefaultProfile <IAzureContextContainer>]
       [-WhatIf]
       [-Confirm]
       [<CommonParameters>]

    • Example
    New-AzResourceGroup -Name rg-azure-dev-centralindia-002 -Location "Central India"

    fig : Azure - PowerShell to create Resource group
    fig : Azure – PowerShell to create Resource group
    • The above command creates empty resource group – no resources in it
    • We could check the resource listing and see the newly created resource – “rg-azure-dev-centralindia-002” group as
    Azure - new resource group created
    fig : Azure – new resource group created
    fig : AZURE - Resource Group details
    fig : AZURE – Resource Group details

    Other Resource Group PowerShell CMDLETs

    • List All Resource Groups in current subscriptionGet-AzResourceGroup

      Get-AzResourceGroup
         [[-Name] <String>]
         [[-Location] <String>]
         [-Id <String>]
         [-Tag <Hashtable>]
         [-ApiVersion <String>]
         [-Pre]
         [-DefaultProfile <IAzureContextContainer>]
         [<CommonParameters>]

      AZURE - Get-AzResourceGroup - gets all AZURE resource groups in current subscription
      fig : AZURE – Get-AzResourceGroup – gets all AZURE resource groups in current subscription
      • We can get specific resource group details as well as
      fig : AZURE - Getting details of specific Resource Group
      fig : AZURE – Getting details of specific Resource Group
      • Remove Resource Group from current subscriptionRemove-AzResourceGroup – removes resource group and its resources from current subscription
      Remove-AzResourceGroup
            [-Name] <String>
            [-Force]
            [-AsJob]
            [-ApiVersion <String>]
            [-Pre]
            [-DefaultProfile <IAzureContextContainer>]
            [-WhatIf]
            [-Confirm]
            [<CommonParameters>]
            -Id <string>

      • When we execute the command we get prompt as shown in below fig
      AZURE - removing resource group from current subscription
      fig : AZURE – removing resource group from current subscription
      • To avoid prompt we could use “Force” attribute as
      Get-AzResourceGroup -Name "rg-azure-dev-centralindia-003" | Remove-AzResourceGroup -Force

      REFERENCES

      Thanks for reading. If its worth, kindly please like and share 🙂

      HAVE A WONDERFUL TIME AHEAD 🙂

      Prasham Sabadra

      LIFE IS VERY BEAUTIFUL :) ENJOY THE WHOLE JOURNEY :) Founder of Knowledge Junction and live-beautiful-life.com, Author, Learner, Passionate Techie, avid reader. Certified Professional Workshop Facilitator / Public Speaker. Scrum Foundation Professional certificated. Motivational, Behavioral , Technical speaker. Speaks in various events including SharePoint Saturdays, Boot camps, Collages / Schools, local chapter. Can reach me for Microsoft 365, Azure, DevOps, SharePoint, Teams, Power Platform, JavaScript.

      You may also like...

      This site uses Akismet to reduce spam. Learn how your comment data is processed.

      %d bloggers like this: