# Get an error on my first ps1 script

**URL:** <https://forums.powershell.org/t/get-an-error-on-my-first-ps1-script/14706>\
**Category:** PowerShell Help\
**Created:** [July 26, 2020, 12:43am UTC](https://forums.powershell.org/t/get-an-error-on-my-first-ps1-script/14706 "2020-07-26T00:43:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![apex](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@apex](https://forums.powershell.org/u/apex)\
**Post date:** [July 26, 2020, 12:43am UTC](https://forums.powershell.org/t/get-an-error-on-my-first-ps1-script/14706/1 "2020-07-26T00:43:03Z")

</div>

So im trying to use powershell instead of bat file and when i paste the code from it get this error.

Error-Set-Location : A positional parameter cannot be found that accepts argument ‘D:\Apexdev\cfx-server-data’.  
At D:\Apexdev\start.ps1:1 char:1

- cd /d “D:\Apexdev\cfx-server-data”
- 

```auto

```

- CategoryInfo : InvalidArgument: (🙂 [Set-Location], ParameterBindingException
- FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SetLocationCommand

&nbsp;

`cd /d “D:\Apexdev\cfx-server-data”
D:\Apexdev\run.cmd +exec server.cfg`

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [July 26, 2020, 2:24am UTC](https://forums.powershell.org/t/get-an-error-on-my-first-ps1-script/14706/2 "2020-07-26T02:24:51Z")

</div>

Sam, welcome to [Powershell.org](http://Powershell.org). Please take a moment and read the very first post on top of the list of this forum: [Read Me Before Posting! You’ll be Glad You Did!](https://powershell.org/forums/topic/read-me-before-posting-youll-be-glad-you-did).

When you post code, error messages, sample data or console output format it as code, please.  
In the “ **Text** ” view you can use the code tags “ **CODE** ”, in the “ **Visual** ” view you can use the format template “ **Preformatted** ”. You can go back edit your post and fix the formatting - you don’t have to create a new one.  
Thanks in advance.

> [@](#):
>
> So im trying to use powershell instead of bat file and when i paste the code from it get this error.

Using Powershell instead of CMD wihtout using any of the advantages of Powershell does not make that much sense. If you have a working CMD file and no need to add additional functionality keep using it. 😉

In Powershell “ **cd** ” is an alias for Set-Location. Please run `Get-Help Set-Location -ShowWindow` to learn how to use it. In Powershell you do not need to explicitly specify if you want to change the current drive along with the directory. So when you omit the option “ **/d** ” for “ **cd** ” the given path would be the first parameter and therefor taken as the **-Path** parameter of [Set-Location](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/set-location?view=powershell-7). 😉

Anyway - the best solution would be not to use aliasses at all in Powershell. They are considered as bad style and only suitable for commands typed into the console - not for scripts. If you want to read more about best practice and style I recommend [The Unofficial PowerShell Best Practices and Style Guide](https://poshcode.gitbooks.io/powershell-practice-and-style/content/).

If you want to move yourself from using old CMD to new and powerfull Powershell you might take a step back and start with learning the very basics of Powershell first. There a lot of great and free ressources out there for this task. Here you have 2 of them well known for beeing good for beginners:

[Getting Started with PowerShell 3.0](https://channel9.msdn.com/Series/GetStartedPowerShell3)

[Windows PowerShell™ 4: TFM](https://www.sapien.com/books_training/Windows-PowerShell-4)

Don’t worry - they’re not made for the current version of Powershell but the basics are still the same. 😉

---

<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:29pm UTC](https://forums.powershell.org/t/get-an-error-on-my-first-ps1-script/14706/3 "2024-05-16T20:29:11Z")

</div>

Closed on May 16, 2024, 8:29pm UTC


