I have used the Get-WmiObject cmdlet to retrieve the Operating System information. This command works fine for the local machine but returns the error message “Get-WmiObject : Access is denied” when I tried to run the following command to get the OS details for the remote computer.
$PSCredential = Get-Credential "Remote_Computer_Name\UserName"
Get-WmiObject Win32_OperatingSystem -ComputerName "Remote_Computer_Name" -Credential $PSCredential
Received the below error message:
Get-WmiObject : Access is denied. At line:1 char:1 + Get-WmiObject Win32_OperatingSystem -ComputerName “ComputerName” | + CategoryInfo : NotSpecified: (:) [Get-WmiObject], UnauthorizedAccessException + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
Fix/Solution
We recommend you check and follow the below points to fix this problem.
- Ensure that you have opened the PowerShell with “Run as administrator” privilege.
- Ensure that you have passed input for the -Credential parameter and ensure the correct user credentials are provided.
- Set WMI Control permissions (in Remote computer)
- Add the user to the Local “Distributed COM Users” group
Set WMI Control permissions (in Remote computer)
The Get-WmiObject cmdlet gets information about the Windows Management Instrumentation (WMI) classes. So, we need to grant the required permissions in WMI Control for the user that you used to connect the remote machine.
Follow the below steps in the remote machine to set the WMI Control permissions.
- Open the WMI Control console: Click Start -> click Run -> type “wmimgmt.msc” and then click OK.
- In the console tree, right-click on WMI Control (Local) and then select Properties.
- Go to the Security tab and select Security, click Advanced and then click Add.
- Select the user you want to grant access to the WMI and click OK.
- Grant the required permissions, we recommend granting all permissions to ensure that access is given and working fine, then remove permissions later as necessary.
- Ensure the “Apply to” option is set to “This namespace and subnamespaces”
- Finally, click Apply to save the changes.
Add the user to the Local “Distributed COM Users” group
The WMI control uses the DCOM component to retrieve details. So, we need to add the user to the Local “Distributed COM Users” security group on the remote computer.
Use the below PowerShell command to add a user to a local security group.
Add-LocalGroupMember -Group "Distributed COM Users" -Member "UserName"
Run this command to retrieve the group members and ensure that you have successfully added the user as a member.
Get-LocalGroupMember -Group "Distributed COM Users"
That’s all, now check whether the Get-WmiObject command is working fine or not.