PowerTip: Run a PowerShell Script with Space in the Path

PowerTip: Run a PowerShell Script with Space in the Path

Rate This
  • Comments 7

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

Leave a Comment
  • Please add 1 and 5 and type the answer here:
  • Post
  • 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.

Page 1 of 1 (7 items)