iif.ps1
Function IIf { <#PSScriptInfo .Description The IIF function returns the True or False expression depending on the result of the boolean statement. .VERSION 1.0 .GUID 1a169007-9a5d-4933-b8e9-0c2fcfb443de .AUTHOR edgenl .COMPANYNAME .COPYRIGHT .TAGS .LICENSEURI .PROJECTURI .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS .EXTERNALSCRIPTDEPENDENCIES .RELEASENOTES #> <# .Synopsis Inline If statement .Example IIF <Condition> [Return Expression if True] [Return Expression if False] .Example $X = 1 $Result = IIF ($X -eq 1) "Answer=1" "Answer<>1" Will result in --> $Result = "Answer=1" #> param( # The Condition [parameter(Mandatory=$True)] $If, # The expression that will be returned if True $IfTrue, # The expression that will be returned if True $IfFalse ) If ($If -IsNot "Boolean") {$_ = $If} If ($If) {If ($IfTrue -is "ScriptBlock") {&$IfTrue} Else {$IfTrue}} Else {If ($IfFalse -is "ScriptBlock") {&$IfFalse} Else {$IfFalse}} } |