Get an error on my first ps1 script

Welcome Forums General PowerShell Q&A Get an error on my first ps1 script

Viewing 1 reply thread
  • Author
    Posts
    • #244787
      Participant
      Topics: 1
      Replies: 0
      Points: -9
      Rank: Member

      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: (:) [Set-Location], ParameterBindingException
      + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SetLocationCommand

       

      cd /d "D:\Apexdev\cfx-server-data"<br />D:\Apexdev\run.cmd +exec server.cfg

    • #244802
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

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

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

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

Viewing 1 reply thread
  • You must be logged in to reply to this topic.