Launching Powershell with PS1 filepath as variable

Viewed 17

I have a Powershell Gui that populates all PS1 files in a specific folder. This GUI is intended for a easy way to execute any one of those scripts in their own PS window.

Here is my issue.

Test.ps1

write-host "Hello World"
pause 

Script that works:

start powershell {& "c:\build\Test.ps1"}

Script that does not work:

$file = "test.ps1"
start powershell {& "c:\build\$file"}

I am confused why its able to open the script perfectly fine with a given file name, but anytime I throw a variable into the mix, it doesnt work.

I tried many ways including just having it Get-Content and run the script that way, but variables in the start powershell paramater seems to throw things off.

0 Answers
Related