Running PowerShell Scripts from Command Line with Parameters

There are plenty of samples on the Internet about how to run PowerShell scripts from command line. However, I have huge trouble passing parameters, especially when the parameters contain space. After hours of trial and error, here is what I got it working.

powershell -NonInteractive -NoProfile -Command & “””C:\Directory with Space\PowerShellScript.ps1“”” -NoSpaceParameter value1 -Time “””12/9/2010 7:00:00 PM“”” -Comment “””test abc“””

Basically, the Command parameter is surrounded by one double quote, and to use double quote in PowerShell command itself, you need to use triple double quote. Have fun quoting. J

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: