Getting Started with Azure PowerShell

This guide will walk you through the essential steps to install and begin using Azure PowerShell to manage your Azure resources.

What is Azure PowerShell?

Azure PowerShell is a set of cmdlets that leverage the .NET Framework to manage Azure resources. It allows you to connect to your Azure subscription and manage resources using familiar command-line syntax.

Prerequisites

  • An Azure account with an active subscription. If you don't have one, you can create a free account.
  • A supported operating system (Windows, macOS, or Linux).
  • PowerShell 5.1 or later on Windows, or PowerShell Core 6.0 or later on macOS and Linux.

Installation

The recommended way to install Azure PowerShell is by using the PowerShell Gallery.

  1. Open PowerShell as an Administrator:

    On Windows, right-click on the PowerShell icon and select "Run as administrator". On macOS and Linux, you can run PowerShell from your terminal.

  2. Install the Az module:

    Run the following command to install the latest Azure PowerShell module:

    Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force

    If you are prompted about an untrusted repository, type 'Y' and press Enter.

  3. Verify the installation:

    After the installation completes, you can check the installed modules with:

    Get-Module -ListAvailable -Name Az

Connecting to Your Azure Account

Once installed, you need to connect your PowerShell session to your Azure account.

Connect-AzAccount

This command will open a browser window or prompt you to authenticate with your Azure credentials. After successful authentication, you'll see information about your default subscription.

Managing Resources

You can now use Azure PowerShell cmdlets to interact with your Azure resources. Here are a few common examples:

Listing Resource Groups

To see all resource groups in your default subscription:

Get-AzResourceGroup

Creating a Resource Group

To create a new resource group:

New-AzResourceGroup -Name MyResourceGroup -Location "East US"

Listing Virtual Machines

To list all virtual machines in your subscription:

Get-AzVM
Tip: Use the Get-Command -Module Az* cmdlet to discover available Azure PowerShell commands.

Next Steps

Explore the vast capabilities of Azure PowerShell by visiting the following resources: