How to connect to Azure via Powershell (first time)
Requirements:
- PowerShell 5.1
- .NET Framework 4.7.2 or later.
- Azure Powershell Module
Check Powershell Version:
# Open a "powershell" console
# PSVersioncheck
$PSVersionTable.PSVersion
Check .NET Framework Version:
# Check for .NET Framework 4.7.2
Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\' | Get-ItemPropertyValue -Name Release | Foreach-Object { $_ -ge 461814 }
# Check for .NET Framework 4.8
Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\' | Get-ItemPropertyValue -Name Release | Foreach-Object { $_ -ge 528049 }
Install Powershell Azure Module :
# Online: Install needed Powershell Module
Install-Module -Name Az -AllowClobber -Scope AllUsers
# Offline: Download MSI-Installer to install the needed Module with an installer
Save-Module -Name Az -Path '\\someshare\PowerShell\modules' -Force
# Import the module
Import-Module Az
# Check Installation
if (Get-Module -ListAvailable -Name Az*) {
Write-Host "Module exists"
}
else {
Write-Host "Module does not exist"
}
# Connect to Azure with a browser sign in token
Connect-AzAccount
Update Powershell Azure Module :
# Update Powershell Module
Install-Module -Name Az -AllowClobber -Force
Remove an old Powershell Azure Module :
# Update Powershell Module
Uninstall-AzureRm
Unexpected incidents:
If you run into an error during the online installation with the following content:
....
PackageManagement\Install-Package : Cannot convert value "2.0.0-preview" to type "System.Version". Error: "Input string was not in a correct format."
....
You should install the latest version of "PowerShellGet":
# Install latest PowerShellGet Version
Install-Module -Name PowerShellGet -Repository PSGallery -Force
# Close your current PS-Terminal and open a new one to load the new version.
There is a second way to connect to Azure to send textual commands. This is done using the so-called "Azure CLI".
More information about this can be found in the following blogg post.