Powershell - Execute a Script Remotely

Script that will run a script on a remote PC or server then the return code from the remote script

Description

This is a powershell script that will run a script on a remote PC or server then the return code from the remote script will be returned to the local machine as a parameter.

This is very useful when you want to run something on a remote machine but also need a return code as there may be dependencies on the outcome of the remote script.

  • The script can take parameters which are passed into the command for remote running

  • The return code is the return code of the remote session so the remote script should exit with an appropriate exit status so that the correct return code is picked up (see example file test.txt which exits with a status 2)

  • As the return code is a local variable it can be used locally for other purposes such as the exit code of a Uproc


Requirement

This script requires:

  • Powershell

  • WinRM configured to allo remote execution


Use

This script need 2 parameters:

  • -my_remote_pc: Hostname or IP of the remote computer

  • -remote_run: Script to execute on the remote computer


Target environments: Windows (all versions)


Prerequisites: Powershell should be installed on the windows PCs. For remote running adequate security is required to allow a user on one PC to run remote code on another. Credentials can be passed by the script however its never a good idea to hardcode passwords into scripts so the security is better taken care of elsewhere.

Operating Systems


Versions

This plugin has no official releases yet

Created by....

Automic Admin

Automic Admin


Email:
test@testldap.com


Login to View or Leave Comments