Quantcast
Channel: TechNet Blogs
Viewing all articles
Browse latest Browse all 17778

Stay Current! :Detect Hyper-V 2012 Hotfixes if they are installed or not

$
0
0

After reading Cristians excellent blog here --> http://blogs.technet.com/b/cedward/archive/2013/05/24/validating-hyper-v-2012-and-failover-clustering-2012-hotfixes-and-updates-with-powershell.aspx I decided to try and write an addition on to his original script where it would parse the html table directory from the wiki page and just take the current patches!

 

so here is my attempt :)

 

<#

 

 .SYNOPSIS

Runs a Check on a remote server for the necessary hotfixes

 

 .DESCRIPTION

 

This script will check technet against the current
"hotfix" list

 

 .PARAMETER Computername

 

.EXAMPLE

 

 .\CheckHotFix.ps1 -Computername Server01

 

 #>

 

param([Parameter(Position=0,Mandatory=$true)][ValidateNotNullorEmpty()][string]$computername)

 

 

function checkhotfix([string]$computername)

{

    #List All Patches and & Hotfixes From
Remote Server

    $session = 
[activator]::CreateInstance([type]::GetTypeFromProgID(“Microsoft.Update.Session“,$computername))

    $us = $session.CreateUpdateSearcher()

    $qtd = $us.GetTotalHistoryCount()

    $hot = $us.QueryHistory(1, $qtd)

    $patches = $hot |select title

   

    #Path for temp file to change large
string into Array of objects

    $temppath = $env:userprofile +
"\Desktop"

    $tempfile = $temppath +
"\temp.txt"

   

    #Create a new Com object to work
with internet explorer in hidden mode     

    $ie = new-object -com
"InternetExplorer.Application"

   

    $ie.navigate("http://social.technet.microsoft.com/wiki/contents/articles/15576.hyper-v-update-list-for-windows-server-2012.aspx")

    $doc = $ie.document

    sleep 5

    $doc = $ie.document

 

    $tb1 =
$doc.getelementsbytagname("table") |%{$_.InnerHtml}

 

    #exporting first table which is the
Current updates

    $tb1[0] |out-file $tempfile

 

    #importing so we can process as an array

    [array]$in = get-content $tempfile

    remove-item $tempfile

    [array]$heading = $null

    [array]$output = $null

    [array]$kbs = $null

 

    for($i=0;$i -ne $in.count;$i++)

    {

               
    if (($in[$i] -notlike "*tr style*") -or ($in[$i]
-notlike "<tbody>") -or ($in[$i] -ne $null))

               
    {

                               
    if ($in[$i] -like "<td style*")

                               
    {

                                                                               

                                               
    $heading +=
($in[$i]).split(">")[2].split("<")[0]

                               
    }

                               
    elseif ($in[$i] -like "<td>*")

                               
    {

                                               

                                                               
$count = 0

                                                               
$returnobj = new-object psobject

                                               

           
    while($in[$i] -ne "</tr>")

                                                               
{

                                                                               

 

                                                                               
if ($in[$i] -like "<td>*")

                                                                               
{

                                                                                                                                                                                                                               

                                                                                               
$item = ($in[$i].split(">")[1]).split("<")[0]

                       

                        if($item
-like "KB*")

                       
{

                           
$kbtemp = ($item.split(":")[0]).replace(" ","")

                           
$installed = $patches |select-string $kbtemp

                           

                             if
($installed -eq $null)

                           
{

               
                         

                                $returnobj
|add-member -type Noteproperty -name "Installed" -value $false

                           

                            }

                            else

                           
{

                                 
$returnobj |add-member -type Noteproperty -name "Installed" -value
$true

                           
}               

                        

 

 

                       
}

                      

                                                                                               
$returnobj |add-member -type noteproperty -name $heading[$count] -value $item

                                                                                               
$count++                                                            

                                                                               
}

                                                                               
$i++

                                                                               

                                                                                               

                                                               
}

                               
    $output += $returnobj

                               
    }

                               

               
}

 

}

   

$output

}  

            

            

checkhotfix $computername

 

 

 

 

 


Viewing all articles
Browse latest Browse all 17778

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>