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
  • I love the short PowerTips, thanks!

  • @Hieronymus: Me too!

    Short, precise and easy to remmeber!

    Klaus.

  • @Hieronymus Thank you I hope you find them beneficial.

  • @Klaus Thanks for your kind words.

  • I think you're missing a space in there:

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

    produces an error on my machine. but:

    PS > c:\my' folder\myscript.ps1

    works fine. Need to escape the space so PoSh doesn't interpret it as a separate argument or parameter. Unless I'm missing something to make the first one work?

  • And then of course I make my own typo:

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

    Apostrophe is not a grave.

  • @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.

  • 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.

    As in powershell -noexit .\my` powershell` script.ps1

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