Execute function in remote Computer

This is an example of how to execute PowerShell remote code and pass parameters:

How to fix PowerShell remoting not working

If Powershell remoting is not working between two servers check this:

  • Check if winrm service is running. Full name is Windows Remote Management (WS-Management)
  • Execute winrm quickconfig
  • Enable-PSRemoting -Force command on server.
  • Get-ExecutionPolicy -List to check that you can execute…
  • Check that winrm port is the same as listener port
    • Winrm port: winrm get winrm/config
    • Listener port: winrm enumerate winrm/config/listener
    • Change listener port by (from elevated cmd!!!):
      Winrm set winrm/config/listener?Address=*+Transport=HTTP @{Port=”5985″}
  • Check Windows Firewall is not blocking port.
  • Check that choosen port (5985 or 81) is open (Cryping, NMap)
  • Check TrustedHosts list
  • Test with Invoke-Command -ComputerName SERVER -Port 5985 -ScriptBlock {“C:\Program files” |  Get-ChildItem}
  • Test Invoke-Command with Credentials