2

Inside an existing PowerShell script I can call another script with a parameter like this:

.\Folder\Script.ps1 -parameter $data

But how do I use another variable for the folder part it self? The following part is not working:

.\$folder\Script.ps1 -parameter $data

1 Answer 1

1

You could use the Invoke-Command Cmdlet like this:

$command = ".\$folder\Script.ps1 -parameter $data"
Invoke-Command $command
1
  • 1
    I recommend you to escape $data in your string, so it is not expanded: $command = ".\$folder\Script.ps1 -parameter `$data". Currently, you just expand $data to its value. This can produce wrong command like so: .\Folder\Script.ps1 -parameter Value with spaces. And it will not work at all if $data is not a string, but some complex object. You should retain reference to variable instead expanding it to its value. It also will fail if $folder contains spaces, so you better just use invoke operator &.
    – user364455
    Oct 30, 2015 at 9:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .