How do I string multiple commands together ?

Welcome Forums General PowerShell Q&A How do I string multiple commands together ?

  • This topic has 3 replies, 4 voices, and was last updated 3 months ago by
    js
    Participant
    .
Viewing 3 reply threads
  • Author
    Posts
    • #236014
      Participant
      Topics: 1
      Replies: 0
      Points: -8
      Rank: Member

      Hello,

      I’m trying to string multiple commands together and create 1 batch file. I’ve tried ; and &&  with no luck. The commands include: Install-PackageProvider NuGet -Force; Install-Module -Name PSWindowsUpdate; Get-Package -Name PSWindowsUpdate and so on..

      I’ve tried individual new lines and navigated to the ps1 file + executing it..

       

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

      Vick, 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 “PRE“, 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.

      … with no luck.

      I’ve tried individual new lines and navigated to the ps1 file + executing it..

      You may share the complete code and you should share complete error messages if you get some. And you have to elaborate more detailed how you run your script and what happens when you run your script.

    • #236944
      Participant
      Topics: 7
      Replies: 121
      Points: 587
      Helping Hand
      Rank: Major Contributor

      Tried this and it seems to work, your mileage may vary.

      c:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command "& {Get-Host;Get-Host;Get-Host}"

    • #236959
      js
      Participant
      Topics: 32
      Replies: 842
      Points: 2,686
      Helping Hand
      Rank: Community Hero

      What have you tried? Semicolons is all you need unless you’re piping something.

Viewing 3 reply threads
  • The topic ‘How do I string multiple commands together ?’ is closed to new replies.