Last active
September 7, 2018 08:43
-
-
Save elonmallin/2cc2ae1b0f59e23451e87a10f4316ecf to your computer and use it in GitHub Desktop.
Adds the null coalesc operator from C# to Powershell (As close as we get anyway)
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
<# | |
Adds the null coalescing operator. | |
Use e.g: | |
`$Color = $Settings.Color |?? "blue"` | |
#> | |
function NullCoalesc { | |
param ( | |
[Parameter(ValueFromPipeline=$true)]$Value, | |
[Parameter(Position=0)]$Default | |
) | |
if ($Value) { $Value } else { $Default } | |
} | |
Set-Alias -Name "??" -Value NullCoalesc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment