Run PowerShell or batch file remotely

 

To configure Windows PowerShell to receive remote commands in DEV

http://www.howtogeek.com/117192/how-to-run-powershell-commands-on-remote-computers/

  1. Start Windows PowerShell with the "Run as administrator" option.
  2. On server: enable-psremoting
  3. On server: Set-ExecutionPolicy Unrestricted
  4. On server: Set-Item wsman:\localhost\client\trustedhosts * (allows any computer to connect)
  5. On server: Restart-Service WinRM
  6. On client: Set-ExecutionPolicy Unrestricted
  7. On client: Set-Item wsman:\localhost\client\trustedhosts * (allows connections to any server)
  8. On client: Restart-Service WinRM

To run single command

On client: Invoke-Command -ComputerName yourserver.yourdomain.com -ScriptBlock { C:\ |dir }

 

To run multiple commands

On client: Enter-PSSession -ComputerName yourserver.yourdomain.com

….

On client: Exit-PSSession

 

To run a PowerShell script remotely from a client batch file

On client: create a "C:\Local.bat" file

On client: create a "C:\Remote.ps1" file

On client in the Remote.ps1 file: enter your powershell commands that will be executed remotely, like dir C:\

On client in the Local.bat file: @powershell -command "Invoke-Command -ComputerName yourserver.yourdomain.com -FilePath ""C:\Remote.ps1"""

pause

Leave a Reply

Your email address will not be published. Required fields are marked *