PowerTip: Run a PowerShell Script with Space in the Path

PowerTip: Run a PowerShell Script with Space in the Path

  • Comments 9
  • Likes

Summary: Learn how to run a script with a space in the path.

Question: How do I run a script with a space in the path?

Answer 1: PS > c:\my` folder\myscript.ps1

Answer 2: PS> &(“c:\my  folder\myscript.ps1”)

Question: What is the easiest way to create an array?

Answer 1: $array = “1”,”2”,”3”,”4”

Answer 2: $array = 1..4

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • <p>I love the short PowerTips, thanks!</p>

  • <p>@Hieronymus: Me too!</p> <p>Short, precise and easy to remmeber!</p> <p>Klaus.</p>

  • <p>@Hieronymus Thank you I hope you find them beneficial. </p>

  • <p>@Klaus Thanks for your kind words. </p>

  • <p>I think you&#39;re missing a space in there:</p> <p>Answer 1: PS &gt; c:\my`folder\myscript.ps1</p> <p>produces an error on my machine. but:</p> <p>PS &gt; c:\my&#39; folder\myscript.ps1</p> <p>works fine. Need to escape the space so PoSh doesn&#39;t interpret it as a separate argument or parameter. Unless I&#39;m missing something to make the first one work?</p>

  • <p>And then of course I make my own typo:</p> <p>PS &gt; c:\my` folder\myscript.ps1</p> <p>Apostrophe is not a grave.</p>

  • <p>@Angel yes, the space disappeared, and that was the entire point of the tip :-) Thanks for the catch, and I added the space back in to the command. </p>

  • <p>Also this works if you are executing a powershell script from a command interface and the name your script has a space in the path or file name.</p> <p>As in powershell -noexit .\my` powershell` script.ps1</p>

  • You can use Long Path Tool for such problems, it works good.