Invoke-Ternary
SYNOPSIS
Replicate the ternary operator ? in PowerShell
SYNTAX
Invoke-Ternary [[-decider] <ScriptBlock>] [[-ifTrue] <ScriptBlock>] [[-ifFalse] <ScriptBlock>]
[<CommonParameters>]
DESCRIPTION
Replicate the ternary operator ? in PowerShell
EXAMPLES
Example 1
PS C:\> Invoke-Ternary -Decider {(Get-Date).DayOfWeek -in 'Saturday', 'Sunday'} -IfTrue { 'Relax' } -IfFalse { 'Get to work' }
On a weekend, executes the script block for IfTrue, else it executes IfFalse
PARAMETERS
-decider
The script block that is evaluated
Type: ScriptBlock
Parameter Sets: (All)
Aliases:
Required: False
Position: 0
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-ifTrue
The script block that is executed when the decider returns true
Type: ScriptBlock
Parameter Sets: (All)
Aliases:
Required: False
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-ifFalse
The script block that is executed when the decider returns false
Type: ScriptBlock
Parameter Sets: (All)
Aliases:
Required: False
Position: 2
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.