Skip to content

Instantly share code, notes, and snippets.

@echohack
Created July 20, 2015 19:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save echohack/3dcbd0b11200ee9e6def to your computer and use it in GitHub Desktop.
Save echohack/3dcbd0b11200ee9e6def to your computer and use it in GitHub Desktop.
Powershell Null Coalescing
($PhysicalPath, "c:\inetpub\wwwroot" -ne $null)[0] # null coalescing
# Based on the order of operations, this works in following order:
# The , operator creates an array of values to be tested.
# The -ne operator filters out any items from the array that match the specified value--in this case, null. The result is an array of non-null values in the same order as the array created in Step 1.
# [0] is used to select the first element of the filtered array.
# Simplifying that:
# Create an array of possible values, in preferred order
# Exclude all null values from the array
# Take the first item from the resulting array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment