Share via

RPC Error Message when running a PowerShell script

Kaplan, Andrew H 226 Reputation points
2025-12-23T13:52:35.6133333+00:00

Hello.

Several PowerShell scripts have been deployed to monitor remote Windows 11 Pro systems in our environment. One of the scripts is designed to monitor active users. This script is failing with the following error message appearing on-screen:

Failed to query mghroswl3. Details: Error 0x000006BA enumerating sessionnames Error [1722]:The RPC server is unavailable. System.Management.Automation.RemoteException

I confirmed the following on the target system:

  1. The RPC service is running, and it is set to Automatic.
  2. Remote Desktop and Remote Assistance are enabled on the firewall. The Remote Assistance is enabled for Private and Domain networks, but for Public networks.
  3. The system is configured for a Normal startup.
  4. File and Print Sharing along with IPv6 TCP/IP are enabled on the system.
  5. The RemoteRegistry service is running.
  6. The TCP/IP NetBIOS Helper service is running.

What other steps can I take to correct this issue?

Windows for business | Windows Server | Networking | Other
0 comments No comments

5 answers

Sort by: Most helpful
  1. Kaplan, Andrew H 226 Reputation points
    2025-12-29T14:38:54.45+00:00

    Hello.

    Thank-you for your responses. As requested the text of the script is the following:

    <#

    .SYNOPSIS

    Gets the number of active user sessions on a remote computer.

    .DESCRIPTION

    Uses the built-in 'quser' command to query remote sessions.

    Filters only sessions with the "Active" state.

    Includes error handling for offline or inaccessible computers.

    .PARAMETER ComputerName

    The remote computer name or IP address.

    .EXAMPLE

    .\Get-ActiveUserCount.ps1 -ComputerName "Server01"

    #>

    param (

    [Parameter(Mandatory = $true)]

    [string]$ComputerName

    )

    try {

    # Run quser remotely and capture output

    $output = quser /server:$ComputerName 2>&1

    # Check if the command failed

    if ($LASTEXITCODE -ne 0) {

    Write-Error "Failed to query $ComputerName. Details: $output"

    exit 1

    }

    # Filter lines containing 'Active' (case-insensitive)

    $activeUsers = $output | Where-Object { $_ -match '\sActive\s' }

    # Count active sessions

    $count = $activeUsers.Count

    Write-Output "Computer: $ComputerName"

    Write-Output "Active user sessions: $count"

    }

    catch {

    Write-Error "Error querying ${ComputerName}: $_"

    }

    Was this answer helpful?


  2. VPHAN 32,870 Reputation points Independent Advisor
    2025-12-24T14:32:38.84+00:00

    Hello Kaplan, Andrew H,

    I'm following up to see if the winmgmt /resetrepository command successfully resolved the 0x8004100e "Invalid namespace" error on the target system (mghroswl3). As detailed in the previous response, this error confirms that network connectivity is healthy but isolates the root cause to a corrupted WMI repository on the local machine. Rebuilding the repository and restarting the Windows Management Instrumentation service (Restart-Service Winmgmt -Force) is the standard and necessary procedure to restore the namespace functionality required for your monitoring scripts.

    If the issue has been successfully resolved, please consider accepting the answer as it helps other people sharing the same question benefit too. Thank you!

    VP

    Was this answer helpful?


  3. VPHAN 32,870 Reputation points Independent Advisor
    2025-12-23T14:46:51.1566667+00:00

    Hello,

    The shift from an RPC unavailable error to 0x8004100e is significant progress. It confirms that network connectivity and firewall traversal are now successful, but the WMI service on the target machine (mghroswl3) can't locate the requested namespace (likely root\cimv2). This specific error almost invariably indicates a corrupted WMI repository on the target system.

    To resolve this, access the target machine directly via an elevated Command Prompt or PowerShell. First, check the repository status by running winmgmt /verifyrepository. If the output states "WMI repository is inconsistent," run winmgmt /salvagerepository to attempt a repair that preserves existing data. If that fails or if the repository claims to be consistent yet still throws the error, you must force a rebuild by running winmgmt /resetrepository. Once the command completes, restart the WMI service using Restart-Service Winmgmt -Force (or net stop winmgmt /y && net start winmgmt) and attempt the connection via wbemtest again.

    If the issue has been successfully resolved, please consider accepting the answer as it helps other people sharing the same question benefit too. Thank you!

    VP

    Was this answer helpful?

    0 comments No comments

  4. VPHAN 32,870 Reputation points Independent Advisor
    2025-12-23T14:24:32.9066667+00:00

    Hello Kaplan, Andrew H,

    The error 0x000006BA (RPC_S_SERVER_UNAVAILABLE) usually indicates that the initial handshake on TCP port 135 failed or the subsequent dynamic port allocation was blocked. While you have confirmed that File and Print Sharing is enabled, that specific group primarily covers SMB ports (445/139). Remote PowerShell scripts that utilize WMI or CIM queries often require the "Windows Management Instrumentation (WMI)" firewall group to be explicitly allowed, which is distinct from Remote Assistance or File Sharing. Furthermore, on Windows 11, if the network adapter has identified the connection as "Public" rather than "Private" or "Domain," the standard firewall exceptions you enabled will not apply.

    To resolve this, first verify the target system's network profile using the PowerShell command Get-NetConnectionProfile on the target machine. If the NetworkCategory is set to Public, you must change it to Private or DomainAuthenticated using Set-NetConnectionProfile -Name "NetworkName" -NetworkCategory Private. If the profile is correct, you then need to explicitly enable the WMI traffic. Run the following command on the target system (mghroswl3) in an elevated PowerShell prompt: Enable-NetFirewallRule -DisplayGroup "Windows Management Instrumentation (WMI)".

    After adjusting the firewall, verify connectivity from your source machine by running Test-NetConnection -ComputerName mghroswl3 -Port 135. If this returns "TcpTestSucceeded: True," retry your monitoring script. If the port test fails despite the firewall changes, ensure there are no hardware firewalls or VLAN ACLs dropping traffic on TCP port 135 between the two subnets.

    I hope you've found something useful here. If it helps you get more insight into the issue, it's appreciated to accept the answer. Should you have more questions, feel free to leave a message. Have a nice day!

    VP

    Was this answer helpful?


  5. AI answer

    2025-12-23T13:52:46.4833333+00:00

    To resolve the RPC server unavailable error (0x000006BA) when running your PowerShell script, consider the following troubleshooting steps:

    1. Check Network Connectivity: Ensure that the target system (mghroswl3) is reachable over the network. You can use the ping command to verify connectivity.
    2. Firewall Settings: Although you mentioned that Remote Desktop and Remote Assistance are enabled, ensure that the firewall is not blocking the dynamic ports used by RPC. The default RPC communication uses TCP port 135 and a range of dynamic ports (49152-65535 by default in Windows). Ensure these ports are open in the firewall settings.
    3. Service Dependencies: Verify that all necessary services for RPC are running. In addition to the RPC service, ensure that the following services are also running:
      • DCOM Server Process Launcher
      • RPC Endpoint Mapper
    4. Check for Network Issues: Use tools like tracert to check for any network issues that may be preventing communication between the systems. Look for any devices that may be dropping packets.
    5. Review Event Logs: Check the Event Viewer on both the source and target systems for any related errors or warnings that might provide more context about the issue.
    6. Dynamic Port Configuration: If your environment has specific configurations for dynamic ports, ensure that they are correctly set up. You can refer to the registry settings related to RPC to confirm this.
    7. Test with Other Scripts: Try running other PowerShell scripts that utilize RPC to determine if the issue is specific to the active users monitoring script or if it is a broader RPC issue.

    By following these steps, you should be able to identify and resolve the underlying cause of the RPC server unavailable error.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

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