Disassembler0 / Win10-Initial-Setup-Script

PowerShell script for automation of routine tasks done after fresh installations of Windows 10 / Server 2016 / Server 2019
MIT License
4.69k stars 1.08k forks source link

Win10.ps1 script should fail if preset file cannot be loaded #258

Closed nre-ableton closed 4 years ago

nre-ableton commented 5 years ago

The Win10.ps1 script currently loads the preset file with:

    # Load tweak names from the preset file
    Get-Content $preset -ErrorAction Stop | ForEach-Object { AddOrRemoveTweak($_.             Split("#")[0].Trim()) }

If the preset file could not be found or was somehow malformed, -ErrorAction Stop at least causes the script to halt execution, but the script still exits with code 0, so it can "look" like a successful run.

I'm running this script via Ansible, and for some while it was noop'ing on account of this behavior. It would be nice if the script could return with a non-zero code so that other scripts could detect this failure.

Sorry, normally I'd just submit a PR, but I'm pretty inexperienced with PowerShell and I don't know the best way to implement this behavior.

Thanks!