How do I get remote PowerShell scripts to run? Enable-PSRemoting isn't working

We're both on the same domain and I've enabled PSRemoting on both machines, but for some reason my remote scripts won't run. The execution policy is unrestricted, but here are the messages I am getting:

Get-Process : Couldn't connect to remote machine.
At line:1 char:1
+ Get-Process -ComputerName
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-Process], InvalidOperationException
    + FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.PowerShell.Commands.GetProcessCommand

Get-EventLog : The network path was not found.
At line:1 char:1
+ Get-EventLog -LogName Application -ComputerName
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-EventLog], IOException
    + FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.GetEventLogCommand

I'm running PSVersion 5.1 and PSRemotingProtocolVersion 2.3 on both machines, does anyone have any suggestions?

After more research, I enabled remote server management (WinRM) and allowed remote PowerShell access on both machines and it still is giving me the same error messages above for those basic cmdlets above, BUT it will let me enter a session on the remote machine using Enter-PSSession. I'm at a loss here, cause the workaround is decent but idealy I'd like to actually run scripts remotely.


1 Answers How do I get remote PowerShell scripts to run? Enable-PSRemoting isn't working

If you can use Enter-PSSession then PSRemoting is working just fine. However, neither Get-Process nor Get-EventLog use PSRemoting for remote connections in the first place. You can check that by inspecting the network traffic with tools like Wireshark or WinDump. You need access to the ports 139/tcp (NetBIOS session) and 445/tcp (DirectSMB) on the remote host for the cmdlets to work. These ports are probably blocked in the Windows Firewall on the remote host, so you need to change that to enable remote connections to that host.

If you want to use PSRemoting you need to invoke the cmdlets locally on the remote host via Invoke-Command:

Invoke-Command -Computer 10.x.x.x -ScriptBlock {
    Get-EventLog -LogName Application

4 months ago