Forum Discussion
Ken_SQLDBA
Nov 06, 2023Copper Contributor
Get-Service fails but Invoke-Command {Get-Service} succeeds
I'm trying to run a series of PowerShell commands on my desktop computer that connect to one of the corporate servers and checks on the status of the services there. I'm doing a Run As on the PowerSh...
- Nov 06, 2023Hello everyone,
I ended up engaging the entire Infrastructure team from my office and we managed to solve the problem by slightly loosening our firewall rules. According to my firewall admin: The firewall rule required ms service controller to be allowed.
This issue is now resolved. Thanks.
Ken
LainRobertson
Nov 06, 2023Silver Contributor
The two commands use completely different connection protocols:
- Get-Service uses RPC (TCP 135);
- Invoke-Command uses WinRM (TCP 5985).
For my environment, I only allow WinRM as without going into the "why", it's most often faster and - indirectly - more secure. I also tend to configure secure WinRM (TCP 5986 using TLS) and block the default non-TLS endpoint (TCP 5985) using the Windows Advanced Firewall (where possible).
In any event, RPC is still commonly utilised in PowerShell and it meets your brief. Just note - purely for educational purposes - that it's also one of the most historically targeted protocols for exploits.
Cheers,
Lain
Ken_SQLDBA
Nov 07, 2023Copper Contributor
Thanks for the explanation. Would you say that the long term solution is to replace "Get-Service ..." with "Invoke-Command {Get-Service ...}"?