Powershell + WSUS + searching for updates

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Matt Bloomfield Matt Bloomfield 11 months ago.

  • Author
    Posts
  • #33633
    Profile photo of Jeremy Anderson
    Jeremy Anderson
    Participant

    I am connecting to WSUS and searching for updates just fine. This works as expected


    #Connect to the WSUS 3.0 interface.
    [reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") | out-null
    $WsusServerAdminProxy = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer($WsusServer,$UseSSL,$PortNumber);

    I can Search for an Update just fine using this:

    $KBs = $WsusServerAdminProxy.SearchUpdates($KB123456) | ?{-not $_.IsDeclined}

    If KB123456 exist, then $KBS returns a list, and I can select Titles.

    What I want to know, is, if KB123456 does not return any results, how can I flag it? Some sort of output line like :

    If ($kbs -eq $null)
    {
    $kbs | export-csv -append d:\NullUpdates.csv
    }

    The problem is, that does not work. I guess its not returning $Null, but not returning anything.

    Help Please

  • #33635
    Profile photo of Matt Bloomfield
    Matt Bloomfield
    Participant

    I can't test it but from MSDN it looks like an empty collection is returned if no updates are found MSDN – SearchUpdates Method.

    The UpdateCollection object has a Count property so you may be able to use
    if ($kbs.count -eq 0) {...} to test for an empty collection.

You must be logged in to reply to this topic.