Last active
November 13, 2019 20:57
-
-
Save IISResetMe/d6f93e639f75047a48b0 to your computer and use it in GitHub Desktop.
C#-style Null Coalesce (??) operator
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 ?? { | |
$args |Select-Object -First 1 | |
} | |
# Use like: | |
# $Name = ?? (Get-ADUser $_ | Select-Object -Expand Name) "John Doe" | |
# | |
# supports as many fallthroughs as you like (like chained ?? in C#) | |
# $Something =?? $null $null $null 1 | |
# ($Something -eq 1) is now the case |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment