Forgive me, as this isn’t strictly a Veeam topic, but I’m pulling my hair out.
I’m trying to enhance a Windows Update Powershell script. The current script occasionally hangs when we invoke a COM CreateUpdateSearcher() method.
$updateSession = new-object -com "Microsoft.Update.Session"
$Criteria = "IsInstalled=0"
$updates = $updateSession.CreateupdateSearcher().Search($criteria).Updates
This runs synchronously, so I can’t trap the hang. Instead, I want to use the BeginSearch() method that runs asynch (https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iupdatesearcher-beginsearch).
My problem is it requires an ‘IUnknown ISearchCompletedCallback’ object to be passed as one of the parameters. I don’t need this to be invoked, so it can be an empty object, but I can’t work out how to create an empty IUnknown object.
$UpdateSession = New-Object -ComObject "Microsoft.Update.Session"
$objSearcher = $UpdateSession.CreateUpdateSearcher()
$objSearch = $objSearcher.BeginSearch('IsInstalled=0',??,$null)
Can anyone help please!
Rob.