← Back to overview
April 10, 2014 · Extensions Powershell Virtual Machines

Manually installing the VM Agent on your older Microsoft Azure Virtual Machines

Yesterday I covered the new CustomScript extension for the VM Agent and in today's post we'll continue on the VM Agent topic. The VM Agent was introduced a few weeks ago with support to install it when deploying a new machine. But you've probably been thinking, what about my old machines?

Last week during Build, Madhan Arumugam (Lead Program Manager) announced the availability of the manual installer for the VM Agent on the MSDN Forum: VM Agent and VM Extensions – Feedback, Issues, Questions. In this post we'll look at how to install the VM Agent.

Manual Installation

The VM Agent can be downloaded here as an MSI file. Which means you can simply download it on on your VM and run the installer:

That's it for installing the VM Agent. And now you can start playing with the BGInfo extension, the CustomScript extension, … This will work fine if you're only managing a few Virtual Machines, but I doubt you'll want to do this if you're running a large farm.

Automated Installation

The alternative would be to automate the installation using Remote PowerShell. I created the following script that does exactly that for you: it connects to the VM, downloads the installer and installs the VM Agent. Calling the script is simple:

.\Install-VMAgent.ps1 -ServiceName cloudServiceName-VmName vmName -UserName userName -Password password

You can now iterate over all the machines where you want the VM Agent to be installed and then simply call the Install-VMAgent script.

The installer is downloaded to the Temp folder and this is where the installer logs are available:

Here's the script but it's also available as a Gist:

param  
(
    [string]$ServiceName,
    [string]$VmName,
    [string]$UserName,
    [string]$Password
)

$ErrorActionPreference = "Stop"

Write-Host ""  
Write-Host " Installing VM Agent on $VmName ($ServiceName)"  
Write-Host ""

$uri = (Get-AzureWinRMUri -ServiceName $ServiceName -Name $VmName).ToString()
$securePassword = ConvertTo-SecureString -String $Password -AsPlainText -For
$credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $securePassword

Write-Host " - WinRM Uri: $uri"  
Write-Host " - Connecting to VM using Remote PowerShell."  
Write-Host ""

$session = New-PSSession -ConnectionUri $uri -Credential $credential -SessionOption (New-PSSessionOption -SkipCACheck)
Invoke-Command -Session $session -Scriptblock {  
    Write-Host "   > Connected."
    $vmAgentInstallationPath = "$env:temp\VmInstallerPath"
    New-Item -ItemType Directory -Force -Path $vmAgentInstallationPath | Out-Null
    cd $vmAgentInstallationPath
    Write-Host "   > Download path: $vmAgentInstallationPath"
    (New-Object system.net.WebClient).DownloadFile("http://go.microsoft.com/fwlink/p/?LinkId=394789", "$vmAgentInstallationPath\VMAgent.msi");
    Write-Host "   > Download success."
    Write-Host "   > Installing..."
    Start-Process -FilePath "VMAgent.msi" -ArgumentList "/quiet /l* vmagent-installation.log" -Wait
    Write-Host "   > Installation complete. The installation logs can be found in the download path."
}
Remove-PSSession $session

Write-Host ""  
Write-Host " - VM Agent installed. You can now start exploring the VM Extensions."  
Write-Host ""  

Enjoy!

  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket
Comments powered by Disqus