Installing Az CLI and Azure PowerShell

Michael Dacanay
2 min readJul 12, 2023

--

The Az CLI and Azure PowerShell are the 2 CLI (command-line interfaces) for Microsoft Azure. They can be used without the other, and each is supposed to fully interact with Azure services. That means any action done in the Azure Portal can be done with the Az CLI and can also be done with the Azure PowerShell. However, since Azure services continuously get updated, the implementations of each interface may not be exactly in lockstep with the others.

  1. Install Az CLI

Install the Azure CLI for Windows | Microsoft Learn

Microsoft Installer (MSI)

Click the blue button “Latest release of the Azure CLI”. This downloads an installer, and we can accept the defaults.

To setup tab completion: notepad $PROFILE and paste the following:

Register-ArgumentCompleter -Native -CommandName az -ScriptBlock {
param($commandName, $wordToComplete, $cursorPosition)
$completion_file = New-TemporaryFile
$env:ARGCOMPLETE_USE_TEMPFILES = 1
$env:_ARGCOMPLETE_STDOUT_FILENAME = $completion_file
$env:COMP_LINE = $wordToComplete
$env:COMP_POINT = $cursorPosition
$env:_ARGCOMPLETE = 1
$env:_ARGCOMPLETE_SUPPRESS_SPACE = 0
$env:_ARGCOMPLETE_IFS = "`n"
$env:_ARGCOMPLETE_SHELL = 'powershell'
az 2>&1 | Out-Null
Get-Content $completion_file | Sort-Object | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, "ParameterValue", $_)
}
Remove-Item $completion_file, Env:\_ARGCOMPLETE_STDOUT_FILENAME, Env:\ARGCOMPLETE_USE_TEMPFILES, Env:\COMP_LINE, Env:\COMP_POINT, Env:\_ARGCOMPLETE, Env:\_ARGCOMPLETE_SUPPRESS_SPACE, Env:\_ARGCOMPLETE_IFS, Env:\_ARGCOMPLETE_SHELL
}

Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete
az login
PermissionError

If you get this error: PermissionError: [Errno 13] Permission denied, then remove the .azure directory:

Remove-Item .azure -Recurse -Force

Output from az login:

[
{
"cloudName": "AzureCloud",
"homeTenantId": "d2526e37-6c12-4e11-904f-7c3ad2e36cca",
"id": "33afbcd1-48c2-49d0-823e-fb03dbc4c999",
"isDefault": true,
"managedByTenants": [],
"name": "Azure for Students",
"state": "Enabled",
"tenantId": "d2526e37-6c12-4e11-904f-7c3ad2e36cca",
"user": {
"name": "michaeldacanayusa@gmail.com",
"type": "user"
}
}
]

2. Install Azure PowerShell

Install Azure PowerShell on Windows | Microsoft Learn

I used PowerShell 7. On my Windows machine, the default is PowerShell 5 so I needed to install the newer version: Installing PowerShell on Windows — PowerShell | Microsoft Learn.

winget install --id Microsoft.Powershell --source winget
PowerShell 7 is installed.

Open PowerShell 7 from start menu.

Set PowerShell execution policy
Install-Module -Name Az -Repository PSGallery -Force
Update-Module -Name Az -Force
Connect-AzAccount

--

--

Michael Dacanay

Intern at Tesla, Fidelity. Student at North Carolina State University