1

With PSexec tool, I am invoking a powershell session on remote computer and executing a PS1 script. I need to pass argument to this powershell script file. It works fine if the argument does not contain space. If the argument does contain space, everything after space is trimmed.

Below is my command:

$script="<PATH>"
$args = "%ProjectSourcePath%"

cmd /c %psexecpath% \\<REMOTE SERVER>   -u <UNAME> -p <PASSWORD> -h  "c:\windows\system32\windowspowershell\v1.0\powershell.exe" $script $args

where "%ProjectSourcePath%" is the environment variable.

Background: I am using this command in Jenkins Automated Build tool. And have added this script in Windows Powershell script block.

3
  • why do you use cmd /c when you can directly start the psexec? Commented Apr 30, 2015 at 8:23
  • I am not aware of that. How can i directly start psexec please?This command will be run from Jenkins Commented Apr 30, 2015 at 8:31
  • I somehow managed to run psexec directly but still same issue Commented Apr 30, 2015 at 9:24

1 Answer 1

3

First thing first, in order to run psexec straight from the command line, add the sysinternals (or wherever your psexec location) folder to the PATH with this cmd

SET PATH=%PATH%;[FOLDER]

Next up, running the command line...

I've created a really simple script creating file with the nameof the argument im passing

param (
    [string]$name = "defaultname"
 )

$array = "string"

$array | out-file "C:\Temp\Script Location\$name.txt"

When running it from the remote server im doing the following:

psexec \\build -h "C:\windows\system32\windowspowershell\v1.0\powershell.exe" "-File" "C:\temp\script location\script.ps1" "argument with space"

ending up with file named "argument with space.txt"

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.