Monthly Archives: August 2014

Install or update Microsoft Azure Powershell Module with Powershell

DEPRECATED POST – NEW AND UPDATED POST CAN BE FOUND HERE

After “manually” updating/installing my Azure Powershell Module from GitHub a couple of times to often, just in the last 4 months, I decided it’s time make a script for this! Or rather a function which I can reuse. 🙂

Install by simply executing:

Get-AzurePowershellModule -Install

You can also download the installer by omitting the -Install parameter. By omitting the -Install parameter the function will the path to the downloaded installer.
If you want more output you can use the parameter -ShowVersion to output the installed version (if any) and the latest version on GitHub.
You can also use -Verbose if you want even more output.

You’ll find the code below or can download directly from GetAzurePowershellModule.

function Get-AzurePowershellModule
{
    [cmdletbinding()]
    Param(
        [switch]$ShowVersion,
        [switch]$Install,
        [string]$Path=$null
    )
    BEGIN
    {
        If ($ShowVersion.IsPresent)
        {
            $Modules = Get-Module -ListAvailable
            $InstalledVersion = ($Modules | Where-Object {$_.Name -eq "Azure"}).Version.ToString()
            Write-Output "Installed: $InstalledVersion"
        }

    }
    PROCESS {
        Try
        {
            $WebSite = Invoke-WebRequest -Uri "https://github.com/Azure/azure-sdk-tools/releases/latest" -Method Get -TimeoutSec 30
        }
        Catch
        {
            Throw "Failed to get Web Content for Azure Powershell Module: $($_.Exception.Message)"
        }

        if ($ShowVersion.IsPresent)
        {
            $LatestVersion = ($WebSite.Links | Where-Object {$_.href -eq $WebSite.BaseResponse.ResponseUri.AbsolutePath}).innerText
            Write-Verbose "LatestVersion = $LatestVersion"
            Write-Output "Latest: $LatestVersion"
        }

        $DownloadURL = ($WebSite.Links | Where-Object {$_.InnerHTML -eq "Windows Standalone"}).href
        Write-Verbose "DownloadURL = $DownloadURL"

        If ($Path -ne $null)
        {
            if ((Test-Path $Path) -eq $false)
            {
                $OutFilePathRoot = (Get-Item $Path).Directory
            }
        }
        if ($OutFilePathRoot -eq $null)
        {
            $OutFilePathRoot = $env:TEMP
        }
        $OutFilePath = "$($OutFilePathRoot)\$($DownloadURL.Split("/")[-1])"
        Write-Verbose "OutFilePath = $($OutFilePath)"

        Invoke-WebRequest -Uri $DownloadURL -OutFile $OutFilePath -Method Get -TimeoutSec 60

        $LogPath = $OutFilePath.Split(".")
        $LogPath[-1] = "log"
        $LogPath = $LogPath -join "."
        Write-Verbose "LogPath = $($LogPath)"

        If ($Install.IsPresent)
        {
            Start-Process $OutFilePath -ArgumentList "/quiet /norestart /log $($LogPath)" -Wait -PassThru
        }
        else
        {
            Write-Output "Azure Powershell Module downloaded to: $($OutFilePath)"
        }
    }
    END
    {
        If ($Install.IsPresent)
        {
            Remove-Item -Path $OutFilePath -Force -Verbose
        }
    }
}
Advertisements

Microsoft Azure IaaS Cost Estimator Tool released!

Ever wondered what it would cost to run your datacenter on Azure? Good!

Are you running Virtual Machine Manger to manage your virtualization hosts? Even better! (But it doesn’t really matter)

Microsoft has released a cost estimator tool help you get a grasp of what your environment would cost to run on Azure!

Read more about the cost estimator tool at: Microsoft Azure IaaS Cost Estimator Tool