Skip to content

Instantly share code, notes, and snippets.

@Calvindd2f
Created September 17, 2024 13:29
Show Gist options
  • Select an option

  • Save Calvindd2f/316762ebaed93309fa9ee9ca13f703c5 to your computer and use it in GitHub Desktop.

Select an option

Save Calvindd2f/316762ebaed93309fa9ee9ca13f703c5 to your computer and use it in GitHub Desktop.
Invoke-Coalesce function and Invoke-IfTrue function
function Invoke-Coalesce ($value, $default)
{
# Use IsNullOrEmpty instead of -not
if ([String]::IsNullOrEmpty($value)) { $value = $default }
return $value
}
function Invoke-IfTrue ($expression, $valueIfTrue, $valueIfFalse)
{
if ($expression) { return $valueIfTrue }
else { return $valueIfFalse }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment