Azure Tip 8 – Getting Started with Azure Powershell

Now this is a blog post that I procrastinated on for years, so here we go:

It is a part of a series of posts on Azure Powershell:

Azure Tip 10: Advanced Powershell Tricks (Web Services, StopWatch, Remoting, COM Interop)
Azure Tip 9: More Azure Powershell (pipes, filters, output formatting, exporting)
Azure Tip 8: Getting Started with Azure Powershell

The different generations of Azure Powershell

There are different generations of the Azure Powershell Modules and that is important for you to know:

  1. Generation: Use the “Azure“prefix. Example commands:
New-AzureVm
Get-AzureVm

These first generation cmdlets have been around since day 1 of Azure. Those were the days of the Azure Service Manager, before the now famous Azure Resource Manager (ARM) even existed.

2. Generation: Use the “AzureRm” prefix. Example commands:

New-AzureRmVm
Get-AzureRmResourceGroup

These cmdlets where introduced with the Azure Resource Manager (ARM). That is what the RM stands for.

3. Generation: Use the “Az” prefix. Example commands:

New-AzVm
Get-AzResourceGroup

I assume that with the upcoming of the Azure CLI, whose main command is “az”, Microsoft probably decided to align the naming and gave us a new generation of Azure Cmdlets.

This all is important, becuase there are incompatibilities between the different generations, you will still find them in samples and demo code and the script and the runtime have to match. That means you can not run a cmdlet that uses the “Az” prefix on a machine that has an older generation of Azure powershell installed. Keep this in mind if you intend to do IaC and run your scripts on a build server.

Installing Azure Powershell

Installation Documentation: https://docs.microsoft.com/en-us/powershell/azure/install-az-ps

The easiest way to install Azure Powershell on Windows is to use the Powershellget Module. It will download the Azure Module directly from the internet. Execute these two commands:

Install-Module Powershellget -force
Install-Module -Name Az

Connect to your Tenant and Subscription

Once Azure Powershell is installed, start it using either the Powershell Commandline or the Integrated Scripting Environment (ISE). Connect to your Azure Subscription:

Connect-AzAccount #no parameters or use:
Connect-AzAccount -Tenant "tenantId" -Subscription "SubscriptionName or Id"

If you did not specify a Tenant or Subscription, you can set them after the login:

#Show the current subscription
Get-AzContext

#Show available subscriptions
Get-AzSubscription

#Set the current subscription
Set-AzContext -Subscription "name or id"

Get Help

Expecially for beginners, Powershell can be hard. These snippets could help:

#find out how powershell helpl works
Get-Help

#If necessary download the updated help documentation
Update-Help

#Find help about a command
Get-Help New-AzVm 
Get-Help New-AzVm -Detailed
Get-Help New-AzVm -Examples #show examples
Get-Help New-AzVm -Full     #show full help document
Get-Help New-AzVm -Online   #open browser and show help
Get-Help New-AzVm -ShowWindow #open desktop window and show help

#Find a cmdlet
Get-Command #Show all commands
Get-Command *AppPool* #show all commands with wildcards

I think the Get-Help cmdlet with the “-online” and/or the “-ShowWindow” options to be explicitly mentioned. Online opens a browser to the help page:

And ShowWindow opens a desktop window containing the help documentation:

But there are more helpers.

The “Show-Command” cmdlet will open a Windows that contains a textbox for all the commands parameters:

Show-Command New-AzVm

Category:Business
PREVIOUS POST
ExpertsLIVE Switzerland 2020: How not to get lost in Azure
NEXT POST
Azure Tip 9 – More Azure Powershell (pipes, filters, output formatting, exporting)

0 Comment

LEAVE A REPLY

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

15 49.0138 8.38624 1 0 4000 1 https://www.12qw.ch 300 0