newbie: Starting a script with spaces in pathname

This topic contains 6 replies, has 3 voices, and was last updated by  John L. 4 weeks, 1 day ago.

  • Author
    Posts
  • #99519

    John L.
    Participant

    I'm trying to start a script (with one positional argument) from the command line thusly:

    C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command "& {C:\Users\John\Documents\My Programs\myScript.ps1 330g000000rXr89}"

    The attempt fails due to the space in the pathname for the script. Various attempts at single-, double-quotes, doubled double-quotes, and using the DOS ^ escape character, have failed.

    Thanks in advance.

  • #99525

    Jeremy Corbello
    Participant

    When calling a PowerShell script from the command line, this is how I do it:

    powershell.exe -file "c:\Temp\Test Path\test.ps1"

    You're trying to tell PowerShell to launch a file, not a command. Just tested and it works with the space in the file path.

  • #99526

    John L.
    Participant

    Thanks, but that's how I started this mis-adventure. When I attempt the following:

     C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file "C:\Users\John\Documents\My Programs\myScript.ps1 0330g000000rXr89"

    I get the error:

    Processing -File 'C:\Users\John\Documents\My Programs\myScript.ps1 0330g000000rXr89' failed because the file does not have a '.ps1' extension. Specify a valid Windows PowerShell script file name, and then try again.

    which clearly isn't correct. My original question arose working around this problem. BTW, the original works when there is not a space in the file pathname.

    I'm using PowerShell 3.0.

    Ideas?

    • #99537

      John L.
      Participant

      I thought I had tried this, but it must of slipped through the cracks. This works:

      C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file "C:\Users\John\Documents\My Programs\myScript.ps1" "0330g000000rXr89"

      Thanks to all that responded.

  • #99529

    Brett
    Participant

    Your file name does not end with .ps1. Try removing 0330g000000rXr89 from the end of the filename and see if that works.

    • #99532

      John L.
      Participant

      0330g000000rXr89 is intended to be a positional parameter.

  • #99534

    Brett
    Participant

    I am not sure about the positional parameter but the error you posted starts with "failed because the file does not have a '.ps1' extension."

You must be logged in to reply to this topic.