Reputation: 1
I have plenty of ps1 scipts which I execute one by one manually, they have $ErrorActionPreference = "Stop"
in their syntax so if something goes wrong they shall stop.
What I want help with is to create a ps1 script that can run all of these scripts sequentially. So if one script fails the "master script" must stop and not continue with next script.
Upvotes: 0
Views: 1953
Reputation: 819
If you have 4 files like:
1WriteHello.ps1
Write-Host "Hello " -NoNewLine
2WriteWorld.ps1
Write-Host "World!"
3WriteError.ps1
Write-Error "Something went wrong."
4WriteANumber.ps1
Write-Host "123"
You can run it with command:
$ErrorActionPreference = 'Stop'; Get-Item 'C:\Path\*.ps1' |% { & $_.FullName }
In your example:
$Scripts = 'D:\temp\download_script.ps1', 'D:\temp\upload_script.ps1', 'D:\temp\reset_scripts.ps1'
$ErrorActionPreference = 'Stop'
$Scripts |% { & $_ }
Upvotes: 0