Azure Powershell Module
Readme
06/04/2025
Azure Powershell Module¶
The following provide documentation on using Azure Powershell in my home lab.
Installation¶
Azure Powershell module can be installed using an Ansible playbook.
ansible-playbook -i inventory/ansible/inventory.ini -k playbooks/azure/deploy_azure_ps.yml
Note that this installs Powershell prior to installing the the Azure Powershell Module. Installation is user based. This means that each user gets their own Powershell environment.
Using Azure Powershell¶
Start using Azure Powershell by starting Powershell from the console.
pwsh
Azure Powershell Commands¶
The following is a list of commonly used Azzure Powershell commands.
Signing In¶
Interactive sign-in is not supported and device authentication must be used:
Connect-AzAccount -UseDeviceAuthentication
Create a Key Vault¶
Use the following command to create a key vault.
New-AzKeyVault -Name "<your-unique-keyvault-name>" -ResourceGroupName "myResourceGroup" -Location "EastUS"
See `https://learn.microsoft.com/en-us/powershell/azure/get-started-azureps?view=azps-14.1.0#find-commands for further details.
You will be prompted to Login to Azure and provided an authentication code. To sign in, use a web browser to open the page https://microsoft.com/devicelogin. After logging in, enter the code shown to authenticate.
After successfully logging in, a confirmation message showing the Subscription name and Tenant is displayed.
Get Commands¶
To discover commands, use the Get-Command cmdlet. For example, list commands related to virtual machines using the following command
Get-Command -Verb Get -Noun AzVM* -Module Az.Compute
Other examples are availabe in https://learn.microsoft.com/en-us/powershell/azure/get-started-azureps?view=azps-14.1.0#find-commands.
Uninstall Azure Powershell¶
The following was excerpted from https://learn.microsoft.com/en-us/powershell/azure/uninstall-az-ps?view=azps-14.1.0.
Enumerate all Az modules.
($AzVersions |
ForEach-Object {
Import-Clixml -Path (Join-Path -Path $_.InstalledLocation -ChildPath PSGetModuleInfo.xml)
}).Dependencies.Name | Sort-Object -Descending -Unique -OutVariable AzModules
Uninstall and remove all Az modules.
$AzModules |
ForEach-Object {
Remove-Module -Name $_ -ErrorAction SilentlyContinue
Write-Output "Attempting to uninstall module: $_"
Uninstall-Module -Name $_ -AllVersions
}
Finally, remove the Az Powershell module
Remove-Module -Name Az -ErrorAction SilentlyContinue
Uninstall-Module -Name Az -AllVersions