Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Passing variables to Start-Process (to run another script)

$
0
0

Hi scripters!

I'm writing a Powershell script in which another powershell script needs to be started. I am using the Start-Process cmdlet to start the other script. The other script needs a command line parameter to work, in this case a UNC path to a folder. 

$scriptPath=Join-Path $scriptDirectory 'theOtherscript.ps1'
$commandArgs = """-file $scriptPath""", " \\$Server\$Share"""
Start-Process powershell.exe -ArgumentList $commandArgs

When I use the Powershell ISE to manually type in the command without using the $commandArgs variable, it works just fine. The other script is started and does its thing. But when I use the $commandArgs variable, a separate powershell window opens, but the script doesn't seem to run properly. When I look into the $commandArgs variable, it appears to contain the same stuff I that I used to manually run the command, so I don't understand what the difference is. 

By the way, the excessive use of quotes is because the UNC path may contain spaces, to I needed to use the quotes to let the script now its actually one folder. 

Does anybody have any idea what I am doing wrong here?

Many thanks in advance. 

--Richard



Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>