Last active
April 13, 2025 19:14
-
-
Save sassdawe/0d69d05339e0e5c7a1ee18a9926bf759 to your computer and use it in GitHub Desktop.
Ternary operator for Windows PowerShell v2 and beyond, maybe even for v1
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
<################################################################################## | |
# | |
# Script name: ternary.ps1 | |
# source http://blogs.technet.com/b/heyscriptingguy/archive/2009/06/15/hey-scripting-guy-event-2-solutions-from-expert-commentators-beginner-and-advanced-the-long-jump.aspx | |
# | |
##################################################################################> | |
set-alias ?: Invoke-Ternary -Option AllScope -Description "PSCX filter alias" | |
filter Invoke-Ternary ([scriptblock]$decider, [scriptblock]$ifTrue, [scriptblock]$ifFalse) { | |
if (&$decider) { | |
&$ifTrue | |
} | |
else { | |
&$ifFalse | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment