Powershell + WSUS + searching for updates

Welcome Forums General PowerShell Q&A Powershell + WSUS + searching for updates

Viewing 1 reply thread
  • Author
    Posts
    • #33633
      Participant
      Topics: 1
      Replies: 0
      Points: 0
      Rank: Member

      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
      Participant
      Topics: 1
      Replies: 302
      Points: 145
      Helping Hand
      Rank: 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.

Viewing 1 reply thread
  • The topic ‘Powershell + WSUS + searching for updates’ is closed to new replies.