Created
August 8, 2022 17:14
-
-
Save xinmyname/99d699225f4fcd416821ebfce5f71633 to your computer and use it in GitHub Desktop.
Coalesce PowerShell arguments
This file contains 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
function Coalesce-Args { | |
$result = $null | |
foreach($arg in $args) { | |
if ($arg -is [ScriptBlock]) { | |
$result = & $arg | |
} else { | |
$result = $arg | |
} | |
if ($result) { break } | |
} | |
$result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment