Created
August 14, 2014 11:36
-
-
Save mjvh80/9c826b3e0de4e32ce208 to your computer and use it in GitHub Desktop.
PowerShell cleanup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$cleanup = {} | |
trap { &$cleanup; } | |
# do stuff | |
$cleanup = add-cleanop { <# delete stuff #> } $cleanup; | |
function add-cleanop($cleanop, $existing = {}) { | |
{ | |
try { | |
&$cleanop; | |
} catch { | |
Write-Warning "Cleanup failed: $_"; | |
} | |
&$existing; | |
}.GetNewClosure(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment