• 9849-xxx-xxx
  • noreply@example.com
  • Tyagal, Patan, Lalitpur

Azure PowerShell

PowerShell is a cross-platform CLI management tool for interacting with Azure resources. This tool can be used instead of the GUI of the Azure portal or desktop/mobile apps for creating and managing your Azure environments. Azure PowerShell is a module that’s installed as part of Windows PowerShell; the Az PowerShell module contains a set of cmdlets (pronounced as commandlets) for PowerShell that allow you to manage resources from within PowerShell directly at the CLI without the need to access the portal.

PowerShell is a popular management tool when the focus is on Windows systems and is designed for complex automation tasks. It can be used interactively, meaning commands can be entered manually by typing them directly into the shell command prompt. Providing cross-platform support (from PowerShell Core 6.x and PowerShell 7.x) means that you can install and use the PowerShell Az module on Windows, Linux, or macOS to interact with your Azure environments.

You can also access the CLI through the portal using Cloud Shell, which provides access to the Az PowerShell module cmdlets; we will cover this in the Azure Cloud Shell section.

PowerShell 7 is the recommended version of PowerShell to use with Az PowerShell on all platforms; that is, Windows, macOS, and Linux. The Az module is based on the .NET Standard library.

PowerShell 7.0.6 or 7.1.3 or later is required for Az module 6.0.0 and later; however, PowerShell 5.1 is still supported.

To use the PowerShell Az module, you must install it (it is pre-installed in Azure Cloud Shell). The preferred installation method for the Az module is to use the Install-Module cmdlet, and the recommended installation scope is for the current user only. You will learn how to install the Azure PowerShell module and some simple PowerShell commands in the Hands-on exercise section of this chapter.

The syntax (the structure or placement of words, or commands in this case) of PowerShell commands uses the verb-noun pair format, and the data (response or answer to your question) that’s returned is called an object.

The verb (first part) of the pair refers to the action that the cmdlet must perform, such as Get, Set, Show, Find, New, and Resize; the noun (second part) of the pair refers to the entity that the action is performed is; that is, do this to that.

A simple example of this is Get-<Verb>, which can be used to get the following approved PowerShell command verbs:

  • Connect-AzAccount can be used to log in to Azure.
  • Get-AzResourceGroup will list all resource groups.
  • NewAzResourceGroup will create a new resource group.
  • New-AzVM will create a new VM.

You can also check the PowerShell version by running the following command from within PowerShell:

$PSVersionTable.PSVersion

These are just a few PowerShell examples. We will look at some of these commands in the hands-on exercise in this chapter.

PowerShell can also run PowerShell scripts; these scripts contain PowerShell cmdlets and code and can only be run (executed) from within PowerShell. Scripts automate repetitive or complex tasks that have many steps and actions to be performed against many different entities. In this case, a series of commands can be assembled in the syntax format of the shell being used, and the script can then be executed by issuing a single command at the PowerShell prompt.

This section looked at the PowerShell CLI as an Azure management tool. The following section looks at the Azure CLI.

Leave a Reply

Your email address will not be published. Required fields are marked *