Question

How is it that one Powershell command works on a remote machine but not the other from the same console?

  1. PS C:> Get-Service -Name WinRM -ComputerName win8

    Status Name DisplayName
    ------ ---- -----------
    Running WinRM Windows Remote Management (WS-Manag...

  2. PS C:> Get-Counter '\Paging File(*)\% Usage' -ComputerName win8 Get-Counter : Unable to connect to the specified computer or the computer is offline. At line:1 char:1

    • Get-Counter '\Paging File(*)\% Usage' -ComputerName win8
    • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : InvalidResult: (:) [Get-Counter], Exception
    • FullyQualifiedErrorId : CounterApiError,Microsoft.PowerShell.Commands.GetCount erCommand
Était-ce utile?

La solution

Get-Service and Get-Counter use a different remoting layer for -ComputerName. Invoke-Command -ComputerName uses the WinRM remoting layer, Get-Service (I believe) is a remote registry call. Get-Counter is a DCOM call, I believe over WMI.

It's a pretty good rule of thumb that if you don't know that a cmdlet with -ComputerName in it is using the PowerShell remoting layer, it's probably not. Many cmdlets had -ComputerName in V1 of PowerShell, and many other remoting layers are more efficient than WinRM, so many -ComputerName parameters use their own layer.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top