How to update all Azure Powershell Az modules?

Viewed 3813

The Azure Powershell Az module comes with an assortment of modules such as Az.Accounts, Az.Aks, etc. Is it possible to update all these Az.* modules at once?

4 Answers

Try this

Get-InstalledModule -Name Az* | Update-Module

You can add -Force after Update-Module, so you won't be prompted with stuff like an untrusted repository every single module.

Update-Module Az -Force

All the individual modules are dependencies of the Az module. So this should do the trick.

Add -Verbose if you want to track progress.

You could try this script, which I wrote a while ago. It goes through every Az.* module and updates to the latest version, including removing previous versions that are still installed.

# Go through all Az.* versions
# Use -ListAvailable to show all versions
Get-Module -Name Az.* -ListAvailable | ForEach-Object {
    $moduleName = $_.Name
    $currentVersion = [Version]$_.Version

    Write-Host "Current version $moduleName [$currentVersion]"

    # Get latest version from gallery
    $latestVersion = [Version](Find-Module -Name $moduleName).Version
    
    # Only proceed if latest version in gallery is greater than your current version
    if ($latestVersion -gt $currentVersion) {
        Write-Host "Found latest version $modulename [$latestVersion] from $($latestVersionModule.Repository)"

        # Check if latest version is already installed before updating
        $latestVersionModule = Get-InstalledModule -Name $moduleName -RequiredVersion $latestVersion -ErrorAction SilentlyContinue
        if ($null -eq $latestVersionModule) {
            Write-Host "Updating $moduleName Module from [$currentVersion] to [$latestVersion]"
            Update-Module -Name $moduleName -RequiredVersion $latestVersion -Force
        }
        else {
            Write-Host "No update needed, $modulename [$latestVersion] already exists"
        }

        # Uninstall outdated version
        Write-Host "Uninstalling $moduleName [$currentVersion]"
        Uninstall-Module -Name $moduleName -RequiredVersion $currentVersion -Force
    }

    # Otherwise we already have most up to date version
    else {
        Write-Host "$moduleName already up to date"
    }
}
Related