Invoke PowerShell from the Command Line with Parameters

There don’t seem to be too many examples of invoking PowerShell from the command line when the PowerShell command itself has parameters. Here’s one that should work (with a line break to fit it to the column width here):

powershell.exe -NoLogo -NoProfile -NonInteractive
.\'MCB.Save Params.ps1'
-Param1 '' -Param2 'Router'

This should be run in the directory containing the script. Note that if the script name includes spaces, you’ll need to enclose the name in quotes—but put the opening quote after the .\.

1 thought on “Invoke PowerShell from the Command Line with Parameters

  1. P4

    [Editor’s note: the following was submitted without explanation. I assume the point is that you can execute any PowerShell command from the command prompt. Changing the URL for safety’s sake.]

    powershell.exe -Command “& {(Invoke-WebRequest -Uri}”

Leave a Reply

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail. You can also subscribe without commenting.

This site uses Akismet to reduce spam. Learn how your comment data is processed.