Geeks With Blogs

Arthur Zubarev Compudicted

This post is going to be the shortest of my all.

Recently, to my surprise, I found myself developing quite a lot with PowerShell, it is not that I have never written scripts, but those mostly were VBScripts.

To start off I can tell that there is a ton of examples on the World Wide Web, and I know of nine free PowerShell books, alas I had no time to read any due to very short project deadlines and when I needed a specific example the search results returned were exhaustive too often, yet incomplete.

At one of the final stages I needed to schedule to execute a PowerShell script that needed to take in a parameter in form of a file path containing spaces and yet the path to the very PS script contained spaces, too.

After fiddling a bit with the bath file I ended up with the following syntax:

Powershell "& 'D:\Documents and Settings\User.Name\My Documents\Development\PSScripts\MyPSScript.ps1'" -InputFile ""D:\Documents and Settings\User.Name\My Documents\InputFile.csv"" -NonInteractive

Note the use of the single quote denoting the path to the PS file and the double quotation marks for its parameter.

Posted on Sunday, September 11, 2011 12:07 AM | Back to top


Comments on this post: How to Run a PowerShell Script From Command Line Both With Spaces in Path And Input Parameter

# re: How to Run a PowerShell Script From Command Line Both With Spaces in Path And Input Parameter
Requesting Gravatar...
Thank you very much for sharing this post; it helped me immensely.
Left by John B. on Feb 18, 2012 12:05 PM

# re: How to Run a PowerShell Script From Command Line Both With Spaces in Path And Input Parameter
Requesting Gravatar...
Thanks for sharing this. You saved my day!
Left by Angie on Aug 15, 2012 10:00 AM

# re: How to Run a PowerShell Script From Command Line Both With Spaces in Path And Input Parameter
Requesting Gravatar...
This has worked for me before (this is from within CMD shell):
Powershell -File "D:\Documents and Settings\etc\MyPSScript.ps1" -InputFile "D:\Documents and Settings\etc\InputFile.csv" -NonInteractive
Left by Ryan S on Jan 17, 2014 2:52 PM

Your comment:
 (will show your gravatar)


Copyright © Compudicted | Powered by: GeeksWithBlogs.net