Automagically Keep the Azure PowerShell Module Up-To-Date

I'm a tidy(ish) person. Tidy desk, tidy mind and all that jazz... as someone once said!

I like to keep my PowerShell house in order. I want the latest help files and the latest versions of my modules.

I've been able to use a cmdlet to keep my help files up-to-date since version 3 of PS. With the advent of version 5 and the PowerShellGet module, I can now automagically keep my modules up-to-date, too.

PowerShellGet lets you find, install and update modules from an online repository. It comes with the Update-Module cmdlet. I've update my $profile so that every time my console host starts as Administrator, I attempt to update the Azure module.

Here's what the snippet looks like:

if (([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`

[Security.Principal.WindowsBuiltInRole] "Administrator"))

{

Start-Job -ScriptBlock {Update-Help -Force}

Start-Job -ScriptBlock {Update-Module Azure -Verbose}

}

 

For both the help update and the module update I run the tasks as jobs in the background. I can then check their status with Get-Job and Receive-Job. Without the -Force parameter, Update-Module will only update the target module if a new version is available. I like to run it with -Verbose so I can see what happened if I retrieve the job.

Easy.

PS - I've also recently added the following lines to keep up with 'The AzureRM Jonses'...

Start-Job -ScriptBlock {Update-Module AzureRM -Verbose}

Start-Job -ScriptBlock {Update-AzureRM -Verbose}*

 

  *I've yet to find a way to prevent this bad-boy updating every time it's executed. You can use the Install-ModuleWithVersionCheck for individual components of AzureRM, but I've not written something to process each module yet...

PPS - In response to my post-script, check out Simon Wahlin's investigatory prowess! Sweet.