Automating Update of Azure-Powershell

Just a quick post to share a useful script. The PowerShell script below will download and update the Azure-PowerShell command-lets to the latest and greatest version. It even does a slick little version compare. I’ll put the disclaimer out there, that I an not the original author of this script and unfortunately I’ve lost the reference. If this is your script or you have a link to the original author’s blog post, pass it along and I’ll be happy to give credit where it is due. At any rate, the script is below:

$AzureModule = Get-Module -Name Azure -ListAvailable
$LatestRelease = Invoke-RestMethod 
    -Uri https://api.github.com/repos/Azure/azure-powershell/releases/latest -Method GET

If ($AzureModule.Version.ToString() -ne $LatestRelease.name)
{
    $OutFile = "{0}\{1}" -f $env:TEMP, $LatestRelease.assets.name
    Invoke-WebRequest -Uri $LatestRelease.assets.browser_download_url -OutFile $Outfile -Method Get
    Start-Process -FilePath msiexec.exe -ArgumentList @("/i $OutFile /qb") -Wait -PassThru
}
else
{
    Write-Host "Azure Powershell module is up to date."

}

Till next time!

Chris

Advertisements

One thought on “Automating Update of Azure-Powershell

  1. Nice work. One small correction is that the existence condition needs to be changed for people without any version yet:

    If (-not $AzureModule.Version -or ($AzureModule.Version.ToString() -ne $LatestRelease.name))

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s