# newbie: Starting a script with spaces in pathname

**URL:** <https://forums.powershell.org/t/newbie-starting-a-script-with-spaces-in-pathname/10570>\
**Category:** PowerShell Help\
**Created:** [April 23, 2018, 10:57am UTC](https://forums.powershell.org/t/newbie-starting-a-script-with-spaces-in-pathname/10570 "2018-04-23T10:57:39Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![john-l](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/john-l/32/351_2.png) [@john-l](https://forums.powershell.org/u/john-l)\
**Post date:** [April 23, 2018, 10:57am UTC](https://forums.powershell.org/t/newbie-starting-a-script-with-spaces-in-pathname/10570/1 "2018-04-23T10:57:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jacorbello](https://avatars.discourse-cdn.com/v4/letter/j/e47774/32.png) [@jacorbello](https://forums.powershell.org/u/jacorbello)\
**Post date:** [April 23, 2018, 11:40am UTC](https://forums.powershell.org/t/newbie-starting-a-script-with-spaces-in-pathname/10570/2 "2018-04-23T11:40:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![john-l](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/john-l/32/351_2.png) [@john-l](https://forums.powershell.org/u/john-l)\
**Post date:** [April 23, 2018, 1:10pm UTC](https://forums.powershell.org/t/newbie-starting-a-script-with-spaces-in-pathname/10570/3 "2018-04-23T13:10:53Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![brettbnkr](https://avatars.discourse-cdn.com/v4/letter/b/58f4c7/32.png) [@brettbnkr](https://forums.powershell.org/u/brettbnkr)\
**Post date:** [April 23, 2018, 1:15pm UTC](https://forums.powershell.org/t/newbie-starting-a-script-with-spaces-in-pathname/10570/4 "2018-04-23T13:15:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![john-l](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/john-l/32/351_2.png) [@john-l](https://forums.powershell.org/u/john-l)\
**Post date:** [April 23, 2018, 1:17pm UTC](https://forums.powershell.org/t/newbie-starting-a-script-with-spaces-in-pathname/10570/5 "2018-04-23T13:17:01Z")

</div>

0330g000000rXr89 is intended to be a positional parameter.

---

<div class="post-metadata">

**Author:** ![brettbnkr](https://avatars.discourse-cdn.com/v4/letter/b/58f4c7/32.png) [@brettbnkr](https://forums.powershell.org/u/brettbnkr)\
**Post date:** [April 23, 2018, 1:26pm UTC](https://forums.powershell.org/t/newbie-starting-a-script-with-spaces-in-pathname/10570/6 "2018-04-23T13:26:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![john-l](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/john-l/32/351_2.png) [@john-l](https://forums.powershell.org/u/john-l)\
**Post date:** [April 23, 2018, 1:27pm UTC](https://forums.powershell.org/t/newbie-starting-a-script-with-spaces-in-pathname/10570/7 "2018-04-23T13:27:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:35pm UTC](https://forums.powershell.org/t/newbie-starting-a-script-with-spaces-in-pathname/10570/8 "2024-05-16T20:35:09Z")

</div>


