.Net Windows Update Querying .Net Windows Update Querying powershell powershell

.Net Windows Update Querying


Here is a VBScript that you can use to install updates with

http://msdn.microsoft.com/en-us/library/aa387102(VS.85).aspx

You can use a COM object very easily in PowerShell. Given the above VBScript Example, you can use that object in PS as well

PS C:\> $updateSession = new-object -com Microsoft.update.SessionPS C:\> $updateSession | get-member   TypeName: System.__ComObject#{918efd1e-b5d8-4c90-8540-aeb9bdc56f9d}Name                       MemberType Definition----                       ---------- ----------CreateUpdateDownloader     Method     IUpdateDownloader CreateUpdateDownloader ()CreateUpdateInstaller      Method     IUpdateInstaller CreateUpdateInstaller ()CreateUpdateSearcher       Method     IUpdateSearcher CreateUpdateSearcher ()CreateUpdateServiceManager Method     IUpdateServiceManager2 CreateUpdateServiceManager ()QueryHistory               Method     IUpdateHistoryEntryCollection QueryHistory (string, int, int)ClientApplicationID        Property   string ClientApplicationID () {get} {set}ReadOnly                   Property   bool ReadOnly () {get}UserLocale                 Property   uint UserLocale () {get} {set}WebProxy                   Property   IWebProxy WebProxy () {get} {set}PS C:\> $searcher = $updateSession.CreateUpdateSearcher()PS C:\> $searcher | gm   TypeName: System.__ComObject#{04c6895d-eaf2-4034-97f3-311de9be413a}Name                                MemberType Definition----                                ---------- ----------BeginSearch                         Method     ISearchJob BeginSearch (string, IUnknown, Variant)EndSearch                           Method     ISearchResult EndSearch (ISearchJob)EscapeString                        Method     string EscapeString (string)GetTotalHistoryCount                Method     int GetTotalHistoryCount ()QueryHistory                        Method     IUpdateHistoryEntryCollection QueryHistory (int, int)Search                              Method     ISearchResult Search (string)CanAutomaticallyUpgradeService      Property   bool CanAutomaticallyUpgradeService () {get} {set}ClientApplicationID                 Property   string ClientApplicationID () {get} {set}IgnoreDownloadPriority              Property   bool IgnoreDownloadPriority () {get} {set}IncludePotentiallySupersededUpdates Property   bool IncludePotentiallySupersededUpdates () {get} {set}Online                              Property   bool Online () {get} {set}SearchScope                         Property   SearchScope SearchScope () {get} {set}ServerSelection                     Property   ServerSelection ServerSelection () {get} {set}ServiceID                           Property   string ServiceID () {get} {set}PS C:\>

You could continue to use get-member to find out all the different options and basically covert that VBScript into PowerShell and tweak it to do whatever you need it to do.

Andy


The Windows Update Agent API may be what you're looking for:

http://msdn.microsoft.com/en-us/library/aa387287%28VS.85%29.aspx

It's a COM interface (not .NET native) but you can consume that from your application.


That is not that trivial at all, but you just can reference to COM/WUAPI 2.0 Type Library, and VS creates a managed wrapper for you, which is copied to build directory as WuApiLib.dll.

Be carefull of memory leaks.