Difference between getting service from remote computer using gsv and icm

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.


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.

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