Just save the commands in a file with a .ps1 extension and then execute it.
Powershell.exe "C:\Temp\MyCmds.ps1."
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi all. need some help running multiple powershell scripts. They are completed commands that I could just copy and paste into powershell and run....one at a time. but there is over 100 and it will take ages but I may just have to do that as it might be quicker then trying to find a solution
Is there an easier way just to put them in a CSV or text file and just hit one powershell command to run them all one after the other.
Just save the commands in a file with a .ps1 extension and then execute it.
Powershell.exe "C:\Temp\MyCmds.ps1."
Hello NikeshKanani-6547,
Thanks for reaching out.
To run multiple scripts sequentially you can use the -Wait parameter on Start-Process like so
$scriptsList =
@(
'C:\Users\WP\Desktop\Scripts\1.ps1'
'C:\Users\WP\Desktop\Scripts\2.ps1'
'C:\Users\WP\Desktop\Scripts\3.ps1'
)
foreach($script in $scriptsList)
{
Start-Process -FilePath "$PSHOME\powershell.exe" -ArgumentList "-command '& $script'" -Wait
}
PowerShell will wait for the current script to finish before running the next one.
--If the reply was helpful, please don’t forget to upvote or accept as answer. --
Before you do this, know that this is a VERY, VERY, VERY BAD IDEA!
Import-CSV C:\Junk\BadIdea.csv |
ForEach-Object{
Invoke-Expression $_.RunThis
}
Here's a CSV example:
RunThis
Get-Content c:\junk\badidea.csv
Get-Date
"123" -replace "2"
Now imagine some smart-a$$ put "Format-Volume -DriveLetter C" in there!!!