Executing the PowerShell Get-Hotfix cmdlet on a remote server

Sert1k 0 Reputation points
2023-09-21T16:52:22.5366667+00:00

Tell me, please, what is the logic of the Get-Hotfix cmdlet with the -ComputerName parameters and, in general, the whole process of accessing the remote server?

I need to contact a non-domain server to get information on the currently installed updates.

I successfully get this using the "Get-Hotfix -ComputerName Server -Credential $Cred_Administrator" command

In the $Cred_Administrator variable I enter the account of the built-in local administrator.

If I create a new user and grant him local administrator rights, then by specifying his data, I already get the "Access Denied" response.

The first question - why? What advantage does the built-in administrator have in this case from the newly created system administrator?

If I change the WinRM settings (reduce security quite a lot), then the command is executed for new local administrators as well. However, I don't want to downgrade security if there are other options.

The second question is why the account should be in local administrators? Doesn't the "Remote Management Users" group make it possible to run remote commands on a server? This Get-Hotfix cmdlet is executed with the least rights when logging in interactively. Remote access to the server is allowed, rights are granted through this group, what is missing?

Windows for business | Windows Server | User experience | PowerShell
Windows for business | Windows Server | User experience | Other
{count} votes

6 answers

Sort by: Most helpful
  1. MotoX80 36,291 Reputation points
    2023-10-02T22:38:51.5933333+00:00

    If you have already run "winrm quickconfig" on the remote machine, then try this with a remote administrator account on your machine.

    $User = ".\admin"
    $PWord = ConvertTo-SecureString -String "admin" -AsPlainText -Force
    $Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord
    Invoke-Command -ComputerName test10 -Credential $Credential -ScriptBlock {get-hotfix}
    
    1 person found this answer helpful.

  2. MotoX80 36,291 Reputation points
    2023-10-03T17:57:22.4766667+00:00

    I'm sorry, I do not understand your last question.

    On my test10 VM, I have an admin account just like you commented, it is named admin.

    I tried running get-hotfix remotely and got this error.

    The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)

    I had to enable the WMI-In firewall rule for the private and public profiles and then it worked.

    User's image

    I tried it with a Testuser account (not an admin) and got access denied. I believe that is due to Windows using "Interactive" to grant access to COM applications. I tried playing with Dcomcnfg and granting access to "everyone" in COM Security but it still didn't work. I don't really want that enabled so I did not go any further.

    User's image

    Adding testuser to the Remote Management Users group allowed Get-Ciminstance to function, but Get-Hotfix still failed.

    User's image

    Update: Since WMI was working, testuser was able to run this query. See if that works for you.

    Get-CimInstance -ComputerName test10 -class WIN32_QuickFixEngineering
    

  3. MotoX80 36,291 Reputation points
    2023-10-06T14:02:22.77+00:00

    Without WINRM QC, everything works under the built-in administrator. It works with the new administrator only after WINRM QC.

    Please remember that there is a lot that I don't know about how your machines have been configured. If you have some policy set that restricts access to your admin user, there is no way that I would know about it. So when you ask why something "didn't work" or got "access denied", the simple answer is that I just don't know. The best that I can offer is try to help you troubleshoot the problem.

    https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-R2-and-2012/dn579255(v=ws.11)?redirectedfrom=MSDN

    User's image

    That says that adding a user to that group does not automatically grant access to everything, you also would need to resolve "This applies only to WMI namespaces that grant access to the user."

    At least for now, I would recommend that you put the issue of the Remote Management group aside, and focus on getting Administrator group members to work.

    On my test VM I stopped and disabled the Windows Remote Management service. That should effectively simulate a WinRM that has not been QC'd.

    User's image

    After doing that, my CimSession calls fail, but straight WMI calls, including WMIC.exe and Get-Hotfix still work.

    cls
    $computer = "test10"
    $User = ".\admin"
    $pswd = "admin"
    $PWord = ConvertTo-SecureString -String $pswd -AsPlainText -Force
    $Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord
    "-----Testing get-wmiobject------"
    Get-WmiObject -ComputerName $computer -Credential $Credential -Class WIN32_OperatingSystem | Format-Table
    "-----Testing wmic------"
    wmic.exe /node:$computer /user:$user /password:$pswd os get name
    "-----Testing get-hotfix------"
    Get-HotFix -ComputerName $computer -Credential $Credential | Select-Object -First 2 | Format-Table
    "-----Testing CimSession------"
    $sess = New-CimSession  -ComputerName $computer  -Credential $Credential
    if ($sess) { 
        Get-CimInstance -CimSession $sess -class WIN32_Product | Format-Table
        Remove-CimSession -CimSession $sess
    }
    "-----List administrator group members to verify that the admin user is a member------"
    $group = Get-WmiObject -ComputerName $computer -Credential $Credential  win32_group -filter 'Name = "Administrators"'
    $group.GetRelated('Win32_UserAccount') | Format-Table
    

    Produces this output.

    -----Testing get-wmiobject------
    
    SystemDirectory     Organization BuildNumber RegisteredUser SerialNumber            Version   
    ---------------     ------------ ----------- -------------- ------------            -------   
    C:\Windows\system32              19045       Admin          00330-80000-00000-AA859 10.0.19045
    
    
    -----Testing wmic------
    Name                                                              
    
    Microsoft Windows 10 Pro|C:\Windows|\Device\Harddisk1\Partition3  
    
    
    
    -----Testing get-hotfix------
    
    Source Description HotFixID  InstalledBy         InstalledOn          
    ------ ----------- --------  -----------         -----------          
    TEST10 Update      KB5029919 NT AUTHORITY\SYSTEM 9/14/2023 12:00:00 AM
    TEST10 Update      KB5028951 NT AUTHORITY\SYSTEM 8/16/2023 12:00:00 AM
    
    
    -----Testing CimSession------
    New-CimSession : WinRM cannot complete the operation. Verify that the specified computer name is valid, that the 
    computer is accessible over the network, and that a firewall exception for the WinRM service is enabled and 
    allows access from this computer. By default, the WinRM firewall exception for public profiles limits access to 
    remote computers within the same local subnet.
    At line:14 char:9
    + $sess = New-CimSession  -ComputerName $computer  -Credential $Credent ...
    +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ConnectionError: (:) [New-CimSession], CimException
        + FullyQualifiedErrorId : HRESULT 0x80338126,Microsoft.Management.Infrastructure.CimCmdlets.NewCimSessionCom 
       mand
        + PSComputerName        : test10
     
    -----List administrator group members to verify that the admin user is a member------
    
    AccountType Caption             Domain SID                                           FullName Name        
    ----------- -------             ------ ---                                           -------- ----        
            512 TEST10\Administrato TEST10 S-1-5-21-3672446222-1547575315-356276567-500           Administrato
            512 TEST10\Admin        TEST10 S-1-5-21-3672446222-1547575315-356276567-1001          Admin       
    

    Hopefully that resolves the issue of "I don't want to run winrm quickconfig". Is your testing successful?

    When you run that script using the Administrator account, does it show that the Admin user is a member of the group?


  4. khov vannak 0 Reputation points
    2023-10-13T18:26:46.5633333+00:00

    -----Testing get-wmiobject------

    SystemDirectory Organization BuildNumber RegisteredUser SerialNumber Version


    C:\Windows\system32 19045 Admin 00330-80000-00000-AA859 10.0.19045

    -----Testing wmic------

    Name

    Microsoft Windows 10 Pro|C:\Windows|\Device\Harddisk1\Partition3

    -----Testing get-hotfix------

    Source Description HotFixID InstalledBy InstalledOn


    TEST10 Update KB5029919 NT AUTHORITY\SYSTEM 9/14/2023 12:00:00 AM

    TEST10 Update KB5028951 NT AUTHORITY\SYSTEM 8/16/2023 12:00:00 AM

    -----Testing CimSession------

    New-CimSession : WinRM cannot complete the operation. Verify that the specified computer name is valid, that the

    computer is accessible over the network, and that a firewall exception for the WinRM service is enabled and

    allows access from this computer. By default, the WinRM firewall exception for public profiles limits access to

    remote computers within the same local subnet.

    At line:14 char:9

    • $sess = New-CimSession -ComputerName $computer -Credential $Credent ...
    •     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      
      • CategoryInfo : ConnectionError: (:) [New-CimSession], CimException
      • FullyQualifiedErrorId : HRESULT 0x80338126,Microsoft.Management.Infrastructure.CimCmdlets.NewCimSessionCom
      mand
      • PSComputerName : test10

    -----List administrator group members to verify that the admin user is a member------

    AccountType Caption Domain SID FullName Name


        512 TEST10\Administrato TEST10 S-1-5-21-3672446222-1547575315-356276567-500           Administrato
    
        512 TEST10\Admin        TEST10 S-1-5-21-3672446222-1547575315-356276567-1001          Admin
    
    0 comments No comments

  5. khov vannak 0 Reputation points
    2023-10-13T18:33:49.06+00:00

    CategoryInfo : ConnectionError: (:) [New-CimSession], CimException

    FullyQualifiedErrorId៖ HRESULT 0x80338126,Microsoft.Management.Infrastructure.CimCmdlets.NewCimSessionCom

    mand

    PSComputerName : khov vannak

    ----- administrator group members to verify that the admin user is a member------

    AccountType Caption Domain SID FullName Nam

    e khov vannak

    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.