Verify all SCVMM Host Agents are up to date

Hi,

now that UR8 is available, I modified my script slightly to also check if the DHCP Extension is correct. If it is shown in red, please manually update it on every host.

 

Usually, I expected that my hosts would report that they need attention and a Host Agent update would be required. As this did not happen, I wrote below script to verify the latest Agents are installed, and optionally offer to do the update.

Please note that before doing the update, you should take the usual precautions to prepare for Host and VM Downtime. Also, you need to have Execution Policy set to allow running PS scripts.

 

Copy and paste below script into checkagentversion.ps1

#-----------------------------------
# Check Version of VMM Host agents v2.
#-----------------------------------
Write-Host "RTM 3.2.7510.0"
Write-Host "UR1 3.2.7620.0"
Write-Host "UR2 3.2.7634.0"
Write-Host "UR3 3.2.7672.0"
Write-Host "UR4 3.2.7768.0"
Write-Host "UR5 3.2.7995.0"
Write-Host "UR6 3.2.8002.0"
Write-Host "UR7 3.2.8071.0"
Write-Host "UR8 3.2.8117.0"

$vmmserver = get-scvmmserver -ComputerName "localhost"
Write-Host "This SCVMM Server Version"  $vmmserver.ProductVersion

$version = $vmmserver.ProductVersion
$outdated = 0

$ManagedHosts = Get-SCVMMManagedComputer

foreach ($Managedhost in $managedHosts)
{

    if ($version -eq $Managedhost.AgentVersion)
    {
        write-Host $Managedhost.ComputerName $Managedhost.AgentVersion
    }
    else
    {
        write-Host $Managedhost.ComputerName $Managedhost.AgentVersion -ForegroundColor Red
        $outdated = 1
    }

    $DHCPExtn = Get-WmiObject -Class win32_product -Filter 'Name = "Microsoft System Center Virtual Machine Manager DHCP Server (x64)"' -computername $Managedhost.ComputerName
   
    if ($DHCPExtn)
    {
            $seperation = ($DHCPExtn.Version).Split("{.}")
            $dhcpversion = [int]$seperation[2]
            if ($dhcpversion -ge 8071)
            {
                write-Host " DHCPExtn " $DHCPExtn.Version
            }
            else
            {
            write-Host " DHCPExtn " $DHCPExtn.Version "Manual uninstall/install required" -ForegroundColor Red
            }
     }
    else
    {
        write-Host " No DHCPExtn "
    }
   

}

if ($outdated -eq 1)
{
    write-host
    Write-Host "Some Managed Hosts have not the latest agent installed"-ForegroundColor Red
    Write-Host "Warning: Updateing now may cause downtime to the Host and the running VMs"-ForegroundColor Red
    $message= "Do you want to update hosts now.?"
    $yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes",""
    $no = New-Object System.Management.Automation.Host.ChoiceDescription "&No",""
    $choices = [System.Management.Automation.Host.ChoiceDescription[]]($yes,$no)
    $result = $Host.UI.PromptForChoice("Update All Hosts with latest Agent",$message,$choices,0)

    # Do the update

    if($result -eq 0)
    {
   
       $Credential = Get-Credential
       foreach ($Managedhost in $managedHosts)
       {
            if ($version -ne $Managedhost.AgentVersion)
            {
            Write-Host "Updating "  $Managedhost.ComputerName
            $VMMManagedHost = Get-SCVMMManagedComputer -ComputerName $Managedhost.ComputerName
            $result=Update-SCVMMManagedComputer -VMMManagedComputer $VMMManagedHost -Credential $Credential
           
            }
       }
   
    }

}
else
{
    write-Host "Agents on managed computers are up to date"
}

# End of script

 

 

 

Additionally, if you are using Network Virtualization check out this blog to ensure having the latest DHCP extenions. https://blogs.technet.com/b/scvmm/archive/2014/07/31/support-tip-vms-deployed-to-hyper-v-networks-experience-delays-acquiring-an-ip-address-after-reboot.aspx

Hope this helps

Cheers

Robert