Hotfix and updates check of Hyper-V and Cluster with Powershell

I read Hyper-V.nu great blog article about Christian Edwards script that checks both hosts and clusters for hotfixes and updates and found some things I wanted to improve in the script, first of all I wanted an object list instead of just some Write-Host with cool colors.. Then I can use the fabulous techniques of PowerShell to just show the once that I do not have installed or make a decent report for my cluster or just standalone hosts.

The next improvement I thought of was the automatic download of all hotfixes.. Well registering at the web page and downloading each hotfix can work for some but not many, so I extended the XML files with the DownloadURL and also changed the script to support either a host or a cluster object. The download parameter will not check what´s installed or not, it will just download all hotfixes that I found URL´s for so bare with me if it is not complete and make a comment or send me a tweet and I will try to update the xml file

Here you can see how I can run it and also as I have the result as objects filter on installed or not

Screen Shot 2013-06-28 at 01.36.51

And here you can see when I check a cluster and also add the parameters for downloading and the path to where the downloaded files shall reside

Screen Shot 2013-06-28 at 01.40.18

And here is a screendump of some of the hotfix files that are downloaded, as you can see in the script I utilize the BITS engine to download the files 🙂

Screen Shot 2013-06-28 at 01.32.35

Updated with hotfixes to 2013-07-15! Here is the script and the xml files with the extended DownloadURL are in this download zip file-> hyperv12updatescheck.

# Remake of Christian Edwards script to make it more flexible
# http://blogs.technet.com/b/cedward/archive/2013/05/31/validating-hyper-v-2012-and-failover-clustering-hotfixes-with-powershell-part-2.aspx
#
# Niklas Akerlund 2013-06-28

param
(
    [parameter(ValueFromPipeline=$true,  
                   Position=0)]
    [string]$Hostname,
    [parameter(ValueFromPipeline=$true, 
                   Position=1)]
    $ClusterName,
    [switch]$Download,
    [string]$DownloadPath
)

#Getting current execution path
$scriptpath = $MyInvocation.MyCommand.Path
$dir = Split-Path $scriptpath
$listofHotfixes = @()

#Loading list of updates from XML files

[xml]$SourceFileHyperV = Get-Content $dir\UpdatesListHyperV.xml
[xml]$SourceFileCluster = Get-Content $dir\UpdatesListCluster.xml

$HyperVHotfixes = $SourceFileHyperV.Updates.Update
$ClusterHotfixes = $SourceFileCluster.Updates.update

#Getting installed Hotfixes from all nodes of the Cluster/hosts
if ($ClusterName){
    $Nodes = Get-Cluster $ClusterName | Get-ClusterNode | Select -ExpandProperty Name
}else
{
    $Nodes = $Hostname
}
foreach($Node in $Nodes)
{
$Hotfixes = Get-HotFix -ComputerName $Node |select HotfixID,description

foreach($RecomendedHotfix in $HyperVHotfixes)
{
        $witness = 0
        foreach($hotfix in $Hotfixes)
        {
                If($RecomendedHotfix.id -eq $hotfix.HotfixID)
                {
                    $obj = [PSCustomObject]@{
                        HyperVNode = $Node
                        HotfixType = "Hyper-V"
                        RecomendedHotfix = $RecomendedHotfix.Id
                        Status = "Installed"
                        Description = $RecomendedHotfix.Description
                        DownloadURL =  $RecomendedHotfix.DownloadURL
                    } 
                   
                   $listOfHotfixes += $obj
                    $witness = 1
                 }
        }  
        if($witness -eq 0)
        {
            
            $obj = [PSCustomObject]@{
                    HyperVNode = $Node
                    HotfixType = "Hyper-V"
                    RecomendedHotfix = $RecomendedHotfix.Id
                    Status = "Not Installed"
                    Description = $RecomendedHotfix.Description
                    DownloadURL =  $RecomendedHotfix.DownloadURL
            } 
                   
            $listofHotfixes += $obj
 
        }
}

foreach($RecomendedClusterHotfix in $ClusterHotfixes)
{
        $witness = 0
        foreach($hotfix in $Hotfixes)
        {
                If($RecomendedClusterHotfix.id -eq $hotfix.HotfixID)
                {
                    $obj = [PSCustomObject]@{
                        HyperVNode = $Node
                        HotfixType = "Cluster"
                        RecomendedHotfix = $RecomendedClusterHotfix.Id
                        Status = "Installed"
                        Description = $RecomendedClusterHotfix.Description
                        DownloadURL =  $RecomendedClusterHotfix.DownloadURL
                    } 
                   
                   $listOfHotfixes += $obj
   
                   $witness = 1
                 }
        }  
        if($witness -eq 0)
        {
            $obj = [PSCustomObject]@{
                HyperVNode = $Node
                HotfixType = "Cluster"
                RecomendedHotfix = $RecomendedClusterHotfix.Id
                Status = "Not Installed"
                Description = $RecomendedClusterHotfix.Description
                DownloadURL =  $RecomendedClusterHotfix.DownloadURL
            } 
                   
            $listOfHotfixes += $obj          
        }
}
}
if ($Download){
    foreach($RecomendedHotfix in $HyperVHotfixes){
        if ($RecomendedHotfix.DownloadURL -ne ""){
            Start-BitsTransfer -Source $RecomendedHotfix.DownloadURL -Destination $DownloadPath 
        }
    }
    foreach($RecomendedClusterHotfix in $ClusterHotfixes){
        if ($RecomendedClusterHotfix.DownloadURL -ne ""){
            Start-BitsTransfer -Source $RecomendedClusterHotfix.DownloadURL -Destination $DownloadPath 
        }
    }
}

$listofHotfixes

 

Comments

Jeb
Reply

Fantastic work!,
Thanks, it worked awesome and big time saver.

Dan Sheehan
Reply

This is awesome.
I have two enhancements requests that would really help us out.
#1 – Add a PowerShell script switch that allows you to specify if you want to check Hyper-V, Windows Clustering, or both. For example we have non-HyperV clusters we would like to use this script for so we are using a single method consistently, and same thing for non-clustered Hyper-V servers.
#2 – Add a PowerShell script switch and XML tag that allows you to filter out Windows Update issued hot fixes. We use WSUS here and so we don’t need to worry about those, and would really just like to focus on what we call “out of band” (meaning not issued through an automated mechanism from Microsoft) hot fixes.

Do you have any plans to potentially host XML files somewhere like an FTP site so we could periodically check to see if there were updates like when there are updates to http://social.technet.microsoft.com/wiki/contents/articles/15576.hyper-v-update-list-for-windows-server-2012.aspx ?

I could make the modifications to the script myself to do these things, but that would be a one off and I figured if we were looking for these features others might be as well (and this is your baby after all).

Thanks for putting this together in the first place!

Dan Sheehan
Reply

I somehow missed the script came from a Technet site and you had added to it. I will cross post my request there as well.

Christoph
Reply

Hi Niklas,

I stumpled across your comment on the technet blog _after_ I modified the script exactly as you did with basically the same features. I would be very interested in updating the script as requested in the comment of Dan Sheehan. Are you interested in updating your blogpost with the new script?

BG Christoph

Vinicius Dell'Aglio
Reply

Hi,

The updates that show as “not installed”, do I need to install all of them or only if I am having some trouble?

Niklas
Reply

You can read the associated KB and see if you need it. Some of them may not apply to your setup and then you do not need to install them 🙂

Marc Bauer
Reply

For me this script has downloaded “Windows6.1-KB976424-x64” on Windows 2012. This is a 2008R2 patch and not a Windows 2012.

Niklas
Reply

So I noticed, the xml files i took from Christian seems to have that in them, I will update my xml to not include that patch!

Wojciech Sciesinski
Reply

Hi!

I’ve started new project on GitHub that hosts this script and I currently work to create some improvements – see https://github.com/it-praktyk/Get-WindowsHotfixes .

Today I’ve updated UpdatesListCluster.xml – list of hotfixes for Windows Server 2012 – information about KB2894464 was added.

Please feel free to colaborate.

Wojciech Sciesinski

Mubashir
Reply

Hi,

do you have similar for Windows 2008 R2 HyperV Platform ?

Leave a comment

name*

email* (not published)

website