How do I string multiple commands together ?

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…

 

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.

[quote quote=236014]… with no luck.

I’ve tried individual new lines and navigated to the ps1 file + executing it…[/quote]

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.

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}”

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