memdocs icon indicating copy to clipboard operation
memdocs copied to clipboard

Not recommended to use win32_Product query.

Open endersstory opened this issue 3 years ago • 1 comments
trafficstars

The recommended detection method relies on a discouraged method Win32_product.

Get-WmiObject -Class Win32_Product | Where-Object {$_.Name -match "Microsoft Update Health Tools"}

As documented in this article Win32_Product should not be used for application detection. Can the recommended detection method be updated. I'm currently using the existence of the "C:\Program Files\Microsoft Update Health Tools\expediteupdater.exe" exists as valid installation detection.

https://learn.microsoft.com/en-us/powershell/scripting/samples/working-with-software-installations?view=powershell-7.2


Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

endersstory avatar Oct 07 '22 18:10 endersstory

@Brenduns Please help us in resolving this issue. Thanks

yogkumgit avatar Oct 13 '22 13:10 yogkumgit

Checking with PM/Dev if there are recomended alternatives.

Brenduns avatar Oct 17 '22 16:10 Brenduns

@endersstory Thanks for raising this as an issue. I've checked with our developers and we've a pending update for content that will provide a method that doesn’t rely on the Win32_Product. While the current method can be used, it is a bit cranky and isn’t ideal. The new method will replace the current details in the published content later this afternoon, and appears as follows

 $Session = New-Object -ComObject Microsoft.Update.Session
 $Searcher = $Session.CreateUpdateSearcher()
 $historyCount = $Searcher.GetTotalHistoryCount()
 $list = $Searcher.QueryHistory(0, $historyCount) | Select-Object -Property "Title"
 foreach ($update in $list)
 {
   if ($update.Title.Contains("4023057"))
   {
      return 1
   }
 }
 return 0 

If the script returns a 1, the device has UHS client. If the script returns a 0, the device doesn’t have UHS client.

Brenduns avatar Oct 18 '22 17:10 Brenduns