Take the 2-minute tour ×

I have the current powershell script

$release = read-host "enter release"
$fullPath = ""
$fullPath = $fullPath + $release
$fullPath = $fullPath + ".bat"
start-process $fullPath

Currently I log in to a remote machine to run this code for this example The code then pulls the files from another remote machine ( What I would like to do is execute this script from my local machine ( and have it run on .2. I have full access to the box so that should make it easier. How can i go about doing this?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

I have used this once in a project. Where i needed to create website on APP server and had to run from a INT server. So i kept the site setup script on App server and ran remotely from INT server.

 $script = 
 $Filetoexe = args[0]
 invoke-expression "$Filetoexe"
 Invoke-Command -ComputerName Computername -credential credentials -ScriptBlock $script -Args "D:\sitesetup.ps1"

save this and run this. The last line "Invoke-Command" will get executed and it will access the remote computer that you have given and will execute the script block .

The script block takes the argument passed in the last line and executes the file in the script block.

What ever function you need to run on the remote system must be done with in the script block.

Hope it is helpful....

share|improve this answer
Needed to change "$Filetoexe = args[0]" to "$Filetoexe = $args[0]" to get this to work –  letsgetsilly Aug 26 '13 at 15:58
add comment

Put the script into a script file say ReleaseProcessing.ps1 and execute it like so:

Invoke-Command -ComputerName -FilePath .\ReleaseProcessing.ps1

You will be prompted to "enter release" on the local computer but the script is transferred to and runs on the remote computer. This requires that you are running PowerShell 2.0 or higher and that you have enabled remoting on by running the Enable-PSRemoting on that machine. Also, since there is another machine involved you could run into 2nd hop credential issues. If that is the case, consider using the -Authentication paramter with a value of CredSSP.

share|improve this answer
add comment

Your Answer


