Created
July 20, 2015 19:00
-
-
Save echohack/3dcbd0b11200ee9e6def to your computer and use it in GitHub Desktop.
Powershell Null Coalescing
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
($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