locked
PS Remoting Invoke-Command ResourceUnavailable Errors RRS feed

  • Question

  • Hi,

    Within the domain, PS remoting is enabled and is working fine for non-administrative users. I can successfully login to other servers in the domain. But when I try to run some of the commands with Invoke-Command, scripts fail with the following error.

     

    Cannot connect to CIM server. Access denied 
        + CategoryInfo          : ResourceUnavailable: (MSFT_NetAdapter:String) [Get-NetAdapter], CimJobException
        + FullyQualifiedErrorId : CimJob_BrokenCimSession,Get-NetAdapter
        + PSComputerName        : <HOSTNAME2>

    Here is the full powershell script I am trying to run on <HOSTNAME1> with remote session on <HOSTNAME2>.

    $password = ConvertTo-SecureString "<PASSWORD>" -AsPlainText -Force
    $cred = New-Object System.Management.Automation.PSCredential("<USERNAME>",$password);
    $targetServers=@("<HOSTNAME2>")
    ForEach($server in $targetServers) {
      $session = New-PSSession $server -Credential $cred
      Invoke-Command -Session $session -ScriptBlock { Get-NetAdapter -Name *eth0* }
    }

    But the same command (Get-NetAdapter -Name *eth0*) works if I run it on local powershell on <HOSTNAME2>. So my user <USERNAME> has access to run this command.

    Similarly if I just try to run the Invoke-Command with another ScriptBlock (e.g. just hostname command) it works. So only some of the commands don't work. Do we need to configure another setting to allow execution of specific commands with Invoke-Command ?

    Here is the working version of this script with "hostname" ScriptBlock.

    $password = ConvertTo-SecureString "<PASSWORD>" -AsPlainText -Force
    $cred = New-Object System.Management.Automation.PSCredential("<USERNAME>",$password);
    $targetServers=@("<HOSTNAME2>")
    ForEach($server in $targetServers) {
      $session = New-PSSession $server -Credential $cred
      Invoke-Command -Session $session -ScriptBlock { hostname }
    }

    Thank you.

    Monday, March 16, 2020 3:55 PM

All replies

  • It sounds like you have WMI issues.  Restart HOSTNAME2 and try again.


    \_(ツ)_/

    Monday, March 16, 2020 4:55 PM
  • Still no luck, first tried to restart WMI service and then the full restart of the HOSTNAME2 but the issue is still the same.
    Tuesday, March 17, 2020 1:53 PM
  • The simple method to test this is to just run direct and check the error.

    If you account has admin access to the remote system this this wil work if the remote system is functioning correcly.

    Get-NetAdapter -CimSession remotepc

    The CmdLet is designed to do direct remoting.


    \_(ツ)_/

    Tuesday, March 17, 2020 9:03 PM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Yang Yang

    Monday, March 30, 2020 6:00 AM
  • No, issue is not resolved.
    Thursday, May 14, 2020 1:12 PM
  • I don't have admin access. Here is what I get when I run this command.

    Get-NetAdapter : <IP>: Cannot connect to CIM server. The WinRM client cannot process the request. Default
    authentication may be used with an IP address under the following conditions: the transport is HTTPS or the
    destination is in the TrustedHosts list, and explicit credentials are provided. Use winrm.cmd to configure
    TrustedHosts. Note that computers in the TrustedHosts list might not be authenticated. For more information on how to
    set TrustedHosts run the following command: winrm help config.
    At line:1 char:1
    + Get-NetAdapter -CimSession <IP>
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ResourceUnavailable: (MSFT_NetAdapter:String) [Get-NetAdapter], CimJobException
        + FullyQualifiedErrorId : CimJob_BrokenCimSession,Get-NetAdapter

    • Edited by ns_ Thursday, May 14, 2020 1:16 PM
    Thursday, May 14, 2020 1:12 PM