2

I'm new to these awesome Power shell world. I have a problem with script and really apreciate your help.

I have a script "cmd4.ps1" that needs to run another script "Transfer.ps1" that needs to receive 3 strings params and it needs to be run as other process thead different to "cmd4.ps1".

cmd4.ps1:

$Script="-File """+$LocalDir+"\Remote\Transfer.ps1"" http://"+$ServerIP+"/Upload/"+$FileName+" "+$ServerIP+" "+$LocalIP

Start-Process powershell.exe -ArgumentList $Script 

After ejecution, the $Script cointain a value similar to

-File "c:\temp re\Remote\Transfer.ps1" http://10.1.1.1/Upload/file.txt 10.1.1.1 10.1.1.10

containing the syntax to use -File parameter to run a script of Powershell.exe, and three parameters that Transfer.ps1 needs ("http://10.1.1.1/Upload/file.txt", 10.1.1.1, 10.1.1.10).

When I write these instructions in PowerShell ISE I can see every values are right and PowerShell.exe is executed with right values, everything work fine!, but if I put these instructions inside "cmd4.ps1" script it doesn't work, I mean something is not right with parameters because I can see it start powershell but it never ends.

2 Answers 2

1

-ArgumentList is expecting an array of string arguments instead of a single string. Try this instead:

$ScriptArgs = @(
    '-File'
    "$LocalDir\Remote\Transfer.ps1"
    "http://$ServerIP/Upload/$FileName $ServerIP $LocalIP"
)

Start-Process powershell.exe -ArgumentList $ScriptArgs

Note that you can simplify the string construction of the args as shown above.

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

Comments

0

Why don't you put this in cmd4.ps1?

& "c:\temp re\Remote\Transfer.ps1" "http://10.1.1.1/Upload/file.txt" "10.1.1.1" "10.1.1.10"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.