0

I am trying to get a list of available updates using

$UpdateSession = New-Object -ComObject 'Microsoft.Update.Session'
Write-Host "[1]"

$UpdateSession.ClientApplicationID = 'MSDN PowerShell Sample'
Write-Host "[2]"

$UpdateSearcher = $UpdateSession.CreateUpdateSearcher()
Write-Host "[3]" 

$SearchResult = $UpdateSearcher.Search("IsInstalled=0 and IsHidden=0")
Write-Host "[4]"

The last instruction $SearchResult = $UpdateSearcher.Search("IsInstalled=0 and IsHidden=0") freezes, returns nothing and I can't figure out why.
Output :

[1]
[2]
[3]
<running...>

I assume it is actually doing something because I can't CTRL+C to stop it. Have to re-start Powershell.

(W7 SP1, .NET Framework 4.6.1, Powershell 4.0)

Any idea ?

Edit: took those lines from the Get-WindowsUpdates.ps1 script

Svart
  • 21
  • 3
  • this works for me in PS 5.0 - do you run this script as a domain admin? Could a policy prevent you from searching updates? – SimonS May 19 '16 at 09:14
  • No I am not. I am able to get the full list of installed updates using get-hotfix. How does the no-working thing works, how can he know wich updates are available, web request or something ? – Svart May 19 '16 at 09:27
  • What is wrong with using the code in the [dupe](http://superuser.com/questions/1071969/command-to-list-missing-windows-hotfixes) to your [last question](http://superuser.com/questions/1078245/get-the-last-microsoft-published-update-within-a-script)? – DavidPostill May 19 '16 at 11:36
  • I found my way to make it work using following following line : `$listeMAJ = Get-HotFix -ComputerName $ip -Credential $cred | Select-Object description,hotfixid,installedby,@{l="InstalledOn";e={[DateTime]::Parse($_.psbase.properties["installedon"].value,$([System.Globalization.CultureInfo]::GetCultureInfo("en-US")))}} $derMAJ = $listeMAJ | Sort-Object -Property installedon | select-object -last 1` (two lines actually). and managed to get the expected results (list of installed updates). Now I got to find if it is the last one to this day or not, wich does not work – Svart May 19 '16 at 12:14
  • I took the 4 lines in my post from the linked script – Svart May 19 '16 at 12:20
  • @SimonS Tried it on a workmate's computer with PS 5.0 and it worked. Upgraded mine to PS 5.0, the problem still occurs. – Svart May 20 '16 at 07:45

0 Answers0