Run Multiple Powershell Scripts Sequentially - on a Folder - Combine Scripts into a Master Script

后端 未结 6 2148
花落未央
花落未央 2021-02-05 08:25

I have 6+ scripts and growing to run on a folder, what is the best way to have them run one after the other.

I have seen and tried this thread - it did not work unfortun

6条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-05 09:00

    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 script

提交回复
热议问题