Skip to content

Instantly share code, notes, and snippets.

@IISResetMe
Last active November 13, 2019 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IISResetMe/d6f93e639f75047a48b0 to your computer and use it in GitHub Desktop.
Save IISResetMe/d6f93e639f75047a48b0 to your computer and use it in GitHub Desktop.
C#-style Null Coalesce (??) operator
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