Microsoft
Software
Hardware
Network
Question : Powershell: How can I run a program with a parameter list that is stored in a variable?
I want to run a program with a specific parameter list from the Powershell prompt. If I run it directly it works just fine.
./myScript.ps1 myParam
If I store the filename in a string it works as well:
$myString = "./myScript.ps1"
&$myString
But if I add the parameter to the string I can't make it work:
$myString = "./myScript.ps1 myParam"
&$myString
Instead, the prompt returns:
The term './myScript.ps1 myParam' is not recognized as a cmdlet, function, operable program, or script file. Verify the term and try again.
What is the best way to do this?
// Mattias
Answer : Powershell: How can I run a program with a parameter list that is stored in a variable?
in this case you need to use invoke-expression
$myString = "./myScript.ps1 myParam"
invoke-expression $myString
& Assumes the entire string is one command.
Random Solutions
Emails rejected by sbcglobal.net emailing from a SBS2003 exchange server
There is no citrix ssl server configured on the specified address.
My cgi script can't find webpage image file
SEO Benefits of adding business address in Google Maps
exchange 2003 being used as a spam relay
Automatic Login with SBS 2003
Converting LONGTEXT to String MYSQL JDBC
Recieve "An exception occurred: 'Execute'" error on one web server (ASP/MySQL)
Broadcom Bluetooth + change COM port
FTP download folders and its contents