Ask Question. Asked 4 years, 4 months ago. Active 7 months ago. Viewed 53k times. How can I fix this? Peter Mortensen Awsmike Awsmike 1 1 gold badge 5 5 silver badges 14 14 bronze badges. Why are you running it from cmd? Add a comment. Active Oldest Votes. The -File parameter If you want to run powershell. Solution 1 is obviously simpler. The -EncodedCommand parameter You can encode your command as Base Nicely done; as an aside: in PowerShell Core , -File is now the default this change was necessary to support Unix shebang lines.
I feel like this is a better answer than the accepted answer. Just putting file path in quotes using -file parameter didn't work at all for me. Hennessey C. Hennessey 1 1 silver badge 2 2 bronze badges. He's trying to use cmd , so I'm assuming he's invoking it from a. Without the ampersand, it will error out. For a DOS console, the ampersand is not required. I think this is where C. Hennessey was going. In your examples, you're mixing quotes and double quoting for no reason.
Add a comment. Active Oldest Votes. Would this do what you want? Sandra Rossi Adil Hindistan Adil Hindistan 5, 4 4 gold badges 22 22 silver badges 27 27 bronze badges. Anthony Neace Anthony Neace 23k 7 7 gold badges silver badges bronze badges. Problem with this solution is that the path is passed in as an argument and I cannot control how it is escaped. While this answers the question as asked, it's worth pointing out that Invoke-Expression is not only the wrong tool to use for the OP's use case, it should generally be avoided.
Alan Alan 1 1 silver badge 3 3 bronze badges. Jacek Plesnar Jacek Plesnar 2 2 silver badges 5 5 bronze badges. CathyQian CathyQian 10 10 silver badges 27 27 bronze badges. Samuel Philipp 10k 12 12 gold badges 30 30 silver badges 50 50 bronze badges. Fischlein J. Fischlein 61 1 1 silver badge 1 1 bronze badge. Thank you very much! This worked to launch a powershell file named wslLauncher. Works for me. There's a hack I've used since the Invoke-Expression works fine for me.
Hope this helps. Can use the. Start Out-Null. There are multiple ways to use the Create method. Office Office Exchange Server. Not an IT pro? United States English.
Post an article. Subscribe to Article RSS. Click Sign In to add the tip, solution, correction or comment that will help other users. Report inappropriate content using these instructions.
PowerShell: Running Executables. How do you know which one to use for the job?
0コメント