PowerShell to wait for each command to end before starting the next?

43 Views Asked by At

say I have 50 lines of ps code I want to run, a few examples below, I dont want to open 50 windows and run them separately, is there a way to just go to the next line once the first one is done?

.\Get-MessageTraceBySubject.ps1 -Days 3 -Subject "*favor*" -OutputFile c:\temp\favor-$(get-date -f yyyy-MM-dd).csv
.\Get-MessageTraceBySubject.ps1 -Days 3 -Subject "*errand*" -OutputFile c:\temp\errand-$(get-date -f yyyy-MM-dd).csv
.\Get-MessageTraceBySubject.ps1 -Days 3 -Subject "*greeting*" -OutputFile c:\temp\greeting-$(get-date -f yyyy-MM-dd).csv

tried -wait it failed

1

There are 1 best solutions below

0
alexzelaya On

Yes, just create a txt file that contains the keywords you are looking for and then loop through the results.

$var = get-content .\keywords.txt
foreach ($filter in $var) {
.\Get-MessageTraceBySubject.ps1 -Days 3 -Subject "*$filter*" -OutputFile "c:\temp\$($filter)-$(get-date -f yyyy-MM-dd).csv"
}