therealjoshuad

//therealjoshuad
therealjoshuad

Forum Replies Created

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • therealjoshuad
    Participant
    Post count: 2

    You could also use this example of a for each loop:

    # Hotfixes you want to search for
    $hotfixlist = ‘kb2693643′,’kb3118754′,’bogushotfix’

    # Gather all hotfixes installed
    $Hotfixes = Get-HotFix

    # Search through all installed hotfixes for the ones you have
    foreach ($hotfix in $hotfixlist){
    $i = $hotfixes | Where-Object -FilterScript {$_.HotFixID -eq $hotfix}
    if($i){$hotfix_Installed = $True}Else{ }
    }

    Original Way: 1404.0431 Milliseconds
    Second Way: 1388.1292 Milliseconds
    Third Way: 209.6517 Milliseconds

    This way, you only perform the Get-Hotfix lookup once, and the real work is just done with a simple where-object filter. Example measuring all three methods:

    $OriginalWay = Measure-Command {
    $hotfix_installed = (Get-Hotfix | where {$_.HotFixId -like “KB2693643”})
    $hotfix_installed = (Get-Hotfix | where {$_.HotFixId -like “KB3116900”})
    $hotfix_installed = (Get-Hotfix | where {$_.HotFixId -like “KB3116908”})
    $hotfix_installed = (Get-Hotfix | where {$_.HotFixId -like “KB3118754”})
    $hotfix_installed = (Get-Hotfix | where {$_.HotFixId -like “KB3120677”})
    $hotfix_installed = (Get-Hotfix | where {$_.HotFixId -like “KB3124200”})
    $hotfix_installed = (Get-Hotfix | where {$_.HotFixId -like “KB3133431”})
    }

    $secondway = Measure-Command {
    $Hotfixes =
    ‘KB2693643’,`
    ‘KB3116900’,`
    ‘KB3116908’,`
    ‘KB3118754’,`
    ‘KB3120677’,`
    ‘KB3124200’,`
    ‘KB3133431’
    foreach($hotfix in $hotfixes){
    if(Get-Hotfix | where-object {$_.HotFixID -like $hotfix}){
    $hotfix_installed = $true
    }
    }
    }

    $thirdway = Measure-Command {
    $HotfixList =
    ‘KB2693643’,`
    ‘KB3116900’,`
    ‘KB3116908’,`
    ‘KB3118754’,`
    ‘KB3120677’,`
    ‘KB3124200’,`
    ‘KB3133431’

    # Gather all hotfixes installed
    $Hotfixes = Get-HotFix

    # Search through all installed hotfixes for the ones you have
    foreach ($hotfix in $hotfixlist){
    $i = $hotfixes | Where-Object -FilterScript {$_.HotFixID -eq $hotfix}
    if($i){$hotfix_Installed = $True}Else{ }
    }
    } # MC

    “Original Way:” + $OriginalWay.TotalMilliseconds
    “Second Way:” + $secondway.TotalMilliseconds
    “Third Way:” + $thirdway.TotalMilliseconds

  • therealjoshuad
    Participant
    Post count: 2
    in reply to: Quiet? #172

    Same here with trying to figure out how to register, but the post from nlt6444 was what I had to do to find it. Great site otherwise though!

Viewing 2 posts - 1 through 2 (of 2 total)