How do I string multiple commands together ?

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

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: 5
      Replies: 2373
      Points: 6,011
      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: 6
      Replies: 104
      Points: 486
      Helping Hand
      Rank: 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: 30
      Replies: 828
      Points: 2,556
      Helping Hand
      Rank: Community Hero

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

      powershell Install-PackageProvider NuGet -Force; Install-Module -Name PSWindowsUpdate; Get-Package -Name PSWindowsUpdate
Viewing 3 reply threads
  • You must be logged in to reply to this topic.