1.    27 Mar 2007 #1
    xformer Guest

    How to handle spaces in command line paths?


    Hello,

    I installed PowerShell to automate some tasks. I only write scripts and
    stumled upon the following "feature": When a script is located in a directory
    that has spaces in it I can't get PowerShell to execute the script. It always
    stops parsing after the first space character.

    Example: A script named "task.ps1" is located in "E:\All Batch Scripts\".

    If I open a Windows explorer and double-click on the file. It doesn't work.
    If I open a PowerShell and enter "E:\All Batch Scripts\task" it doesn't work
    and shows the following message:

    The expression "E:\All" was not recognized as a cmdlet, function, executable
    program or script file. Check the expression and try again.
    At Line:1 Character:7
    + E:\All <<<< Batch Scripts\task

    If I put the script path into double or single quotes PowerShell just echoes
    it.

    I can get it to work by putting the path parts that contain spaces in single
    quotes but that is not a general way to handle path names that contain spaces.

    So my question is: What do I have to do so that PowerShell executes scripts
    which have a path that contains spaces?

    And the second question is how to put that in a link file in the autostart
    directory so that the script is started whenever the user logs on?

    Any help would be greatly appreciated.

    Frank
      My System SpecsSystem Spec

  2.    27 Mar 2007 #2
    John Vottero Guest

    Re: How to handle spaces in command line paths?


    Start with a & and enclose in quotes like this:

    C:\> &"C:\My PowerShell Scripts\Check Disks.ps1"

    "xformer" <xformer@discussions.microsoft.com> wrote in message
    news:7E81A0C4-3C27-49D8-8590-CC7C55AF492A@microsoft.com...
    > Hello,
    >
    > I installed PowerShell to automate some tasks. I only write scripts and
    > stumled upon the following "feature": When a script is located in a
    > directory
    > that has spaces in it I can't get PowerShell to execute the script. It
    > always
    > stops parsing after the first space character.
    >
    > Example: A script named "task.ps1" is located in "E:\All Batch Scripts\".
    >
    > If I open a Windows explorer and double-click on the file. It doesn't
    > work.
    > If I open a PowerShell and enter "E:\All Batch Scripts\task" it doesn't
    > work
    > and shows the following message:
    >
    > The expression "E:\All" was not recognized as a cmdlet, function,
    > executable
    > program or script file. Check the expression and try again.
    > At Line:1 Character:7
    > + E:\All <<<< Batch Scripts\task
    >
    > If I put the script path into double or single quotes PowerShell just
    > echoes
    > it.
    >
    > I can get it to work by putting the path parts that contain spaces in
    > single
    > quotes but that is not a general way to handle path names that contain
    > spaces.
    >
    > So my question is: What do I have to do so that PowerShell executes
    > scripts
    > which have a path that contains spaces?
    >
    > And the second question is how to put that in a link file in the autostart
    > directory so that the script is started whenever the user logs on?
    >
    > Any help would be greatly appreciated.
    >
    > Frank


      My System SpecsSystem Spec

  3.    27 Mar 2007 #3
    RichS Guest

    RE: How to handle spaces in command line paths?


    To run a script in that manner try

    &"c:\test three\test3.ps1"

    & tells Powershell to execute the string rather than just echoing it
    back. if you need parameters etc put them oustide the quotes

    your command is

    %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -command
    &"c:\test three\test3.ps1"


    --
    Richard Siddaway
    Please note that all scripts are supplied "as is" and with no warranty
    Blog: http://richardsiddaway.spaces.live.com/
    PowerShell User Group: http://www.get-psuguk.org.uk


    "xformer" wrote:

    > Hello,
    >
    > I installed PowerShell to automate some tasks. I only write scripts and
    > stumled upon the following "feature": When a script is located in a directory
    > that has spaces in it I can't get PowerShell to execute the script. It always
    > stops parsing after the first space character.
    >
    > Example: A script named "task.ps1" is located in "E:\All Batch Scripts\".
    >
    > If I open a Windows explorer and double-click on the file. It doesn't work.
    > If I open a PowerShell and enter "E:\All Batch Scripts\task" it doesn't work
    > and shows the following message:
    >
    > The expression "E:\All" was not recognized as a cmdlet, function, executable
    > program or script file. Check the expression and try again.
    > At Line:1 Character:7
    > + E:\All <<<< Batch Scripts\task
    >
    > If I put the script path into double or single quotes PowerShell just echoes
    > it.
    >
    > I can get it to work by putting the path parts that contain spaces in single
    > quotes but that is not a general way to handle path names that contain spaces.
    >
    > So my question is: What do I have to do so that PowerShell executes scripts
    > which have a path that contains spaces?
    >
    > And the second question is how to put that in a link file in the autostart
    > directory so that the script is started whenever the user logs on?
    >
    > Any help would be greatly appreciated.
    >
    > Frank

      My System SpecsSystem Spec


Similar Threads
Thread Forum
Problem with paths with spaces SUDO
I have this function... function sud($SomethingToExecuteInElevation,$NoExit){ $location ="`"`"`""+ (Get-Location) +"`"`"`""; if(!$NoExit){...
PowerShell
wscript.run <command with spaces in path>
Hi, I'm trying to do something like: set wshShell = wscript.createObject"wscript.shell") wshShell.Run("C:\Program Files\TightVNC\unis000.exe") ...
VB Script
Running a command from inside a script, command line is corrupted
Hello, I am trying to give Powershell a chance, since it seems like it may have some promise. I have this powershell script that needs to run...
PowerShell
Re: How to run an executable with spaces in the command line
Ah. Yes. Of course. I feel jolly stupid now. Thanks a lot for your help. On 21 Apr, 09:33, Lionel Fourquaux...
PowerShell
How to run an executable with spaces in the command line
I'm trying to run an executable using a variable which holds the command line so that I can build up the options one-by-one. It won't run. I get...
PowerShell
RE: How to handle spaces in command line paths?
Hello, Richard, thank you very much. I didn't see this. I think it would be a good idea if PowerShell would install itself in such a way that it...
PowerShell
Using Paths with Special Characters and/or Spaces
Im pretty new to Powershell, but what I am trying to do is move a list of files in the root, to a folder named after the files. Example Name ...
PowerShell

Our Sites
  • Ten Forums
  • Eight Forums
  • Seven Forums
  • PC Help Forum
  • Help Me Bake
  • Site Links
  • Contact Us
  • Privacy and Cookies
  • About Us
    Windows Vista Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

    Designer Media Ltd
    All times are GMT -5. The time now is 08:05.
    .