Difference between getting service from remote computer using gsv and icm

This topic contains 2 replies, has 3 voices, and was last updated by  Richard Siddaway 8 months, 2 weeks ago.

  • Author
    Posts
  • #63202

    Parth Gandhi
    Participant

    Hi Team,
    Trying to understand the difference between below 2 cmdlets for getting the services on remote machine:
    1)get-service -computername "server1"
    2)invoke-command -scriptblock {get-service} -computername "server1"

    I have enabled wimrm on remote machine, however the 1st option does gives the output where as 2nd gives an error for WinRM.

    thanks,
    Parth

  • #63223

    Fredrik Kacsmarck
    Participant

    Haven't checked that particular cmdlet but e.g. using get-wmiobject and then the same command via invoke-command differs on the protocol used.
    Get-WmiObject uses Remote Procedure Call (RPC) but Invoke-Command uses powershell remoting (HTTP 5895 or HTTPS 5896).
    So most likely the difference is something similar with get-service.

  • #63316

    Richard Siddaway
    Moderator

    Invoke-Command uses WSMAN to communicate with the remote host. You need to have PowerShell remoting enabled on the remote host. On servers since Windows 2012 remoting is enabled by default. Earlier servers and all client editions you need to explicitly enable remoting

    Get-Service – and other cmdlets that have built in remoting options – use RPC/DCOM for communication with the remote host. This is turned OFF by default on Windows server and blocked by the Windows firewall. Other firewall products block RPC\DCOM by default as well
    You're recommended to use Invoke-Command (or a PowerShell remoting session if send multiple requests) rather than the built in remoting options

You must be logged in to reply to this topic.