Author Posts

January 7, 2016 at 9:10 am

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

January 7, 2016 at 10:23 am

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.