WinRM & PowerShell to check new Windows Updates

jrglt 0 Reputation points
2023-06-08T14:26:44.47+00:00

Hello,

I have successfully configured WinRM between two workgroup 2019 servers.

When I try to check the running services from SERVER2 to SERVER1 with the command "Get-Service", all is working fine.

But now, I would like to be able to check if windows updates are available from SERVER2 to SERVER1.

It seems my user doesn't have permissions to use the Windows Update component.

Any help will be much appreciated

PS C:\Users\dopadmin> Invoke-Command -ScriptBlock {$updateSession = New-Object -ComObject Microsoft.Update.Session} -ComputerName SERVER-1 -Credential limiteduser
Creating an instance of the COM component with CLSID {4CB43D7F-7EEE-4906-8698-60DA1C38F2FE} from the IClassFactory
failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).
    + CategoryInfo          : NotSpecified: (:) [New-Object], UnauthorizedAccessException
    + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.NewObjectCommand
    + PSComputerName        : SERVER-1
 

Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
13,726 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,628 questions
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. Limitless Technology 44,696 Reputation points
    2023-06-09T12:36:53.8+00:00

    Hello there,

    The below script might help you out.

    $Session = New-Object -ComObject "Microsoft.Update.Session";

    $Searcher = $Session.CreateUpdateSearcher();

    $historyCount = $Searcher.GetTotalHistoryCount();

    $Searcher.QueryHistory(0, $historyCount) | Select-Object Date,@{name="Operation"; expression={switch($.operation){1 {"Installation"}; 2 {"Uninstallation"}; 3 {"Other"}}}}, @{name="Status"; expression={switch($.resultcode){1 {"In Progress"}; 2 {"Succeeded"}; 3 {"Succeeded With Errors"};4 {"Failed"}; 5 {"Aborted"} }}}, Title, Description | Export-Csv -NoType "$Env:userprofile\Desktop\Windows Updates.csv";

    You can install the PSWindowsUpdate module on Windows 10/11 and Windows Server 2022/2019/2016 from the online repository (PSGallery) using the command:

    Install-Module -Name PSWindowsUpdate -Force

    After the installation is complete, you need to check the package:

    Get-Package -Name PSWindowsUpdate

    Hope this resolves your Query !!

    --If the reply is helpful, please Upvote and Accept it as an answer–

    0 comments No comments

  2. Liam Ng 5 Reputation points
    2024-04-02T22:38:55.2033333+00:00

    I had the same problem when using less-privileged user for PRTG monitoring.

    It seems that the interfaces, methods, and properties of Windows Update Agent (WUA) are accessible only to callers who belong to Administrator group, otherwise, the HRESULT E_ACCESSDENIED is returned.
    Reference: https://learn.microsoft.com/en-us/windows/win32/wua_sdk/secured-methods-and-properties-in-the-wua-api

    So, the only way is to add your limiteduser as local admin on SERVER-1, you should get your result.

    The service account that I use is in the Power User, Remote Management Users, Performance Monitor Users, and Distributed COM Users. Additionally, I have granted access to the \Root\CIMV2 namespace. But still, no luck.

    I hope this finding helps.

    0 comments No comments

  3. Liam Ng 5 Reputation points
    2024-04-02T22:39:12.11+00:00

    Duplicated. Please ignored.

    0 comments No comments

  4. Liam Ng 5 Reputation points
    2024-04-02T22:39:34.7333333+00:00

    Duplicated. Please ignored.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.