Get an error on my first ps1 script

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”
  • CategoryInfo : InvalidArgument: (:slight_smile: [Set-Location], ParameterBindingException
  • FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SetLocationCommand


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

Sam, welcome to 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!.

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.

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. :wink:

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. :wink:

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.

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

Windows PowerShell™ 4: TFM

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