Last active
April 15, 2016 01:37
-
-
Save midnightfreddie/ade19f53b6d4df4612015aa732acfeb6 to your computer and use it in GitHub Desktop.
Experimenting with boolean parameters and switches in reply to https://www.reddit.com/r/PowerShell/comments/4eth2w/switch_parameters_vs_interactive_input/
This file contains hidden or 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
function Get-Hype { | |
param ( | |
[switch]$CleganeBowl, | |
[switch]$KingsMoot | |
) | |
New-Object psobject -Property ([ordered]@{ | |
CleganeBowl = $CleganeBowl | |
CleganeBowlIsPresent = $CleganeBowl.IsPresent | |
CleganeBowlBound = $PSBoundParameters.ContainsKey('CleganeBowl') | |
KingsMoot = $KingsMoot | |
KingsMootIsPresent = $KingsMoot.IsPresent | |
KingsMootBound = $PSBoundParameters.ContainsKey('KingsMoot') | |
}) | |
} | |
Get-Hype | |
# CleganeBowl : False | |
# CleganeBowlIsPresent : False | |
# CleganeBowlBound : False | |
# KingsMoot : False | |
# KingsMootIsPresent : False | |
# KingsMootBound : False | |
Get-Hype -CleganeBowl | |
# CleganeBowl : True | |
# CleganeBowlIsPresent : True | |
# CleganeBowlBound : True | |
# KingsMoot : False | |
# KingsMootIsPresent : False | |
# KingsMootBound : False | |
Get-Hype -CleganeBowl -KingsMoot=$false | |
# CleganeBowl : True | |
# CleganeBowlIsPresent : True | |
# CleganeBowlBound : True | |
# KingsMoot : False | |
# KingsMootIsPresent : False | |
# KingsMootBound : False | |
$Parameters = @{ | |
CleganeBowl = $true | |
KingsMoot = $false | |
} | |
Get-Hype @Parameters | |
# CleganeBowl : True | |
# CleganeBowlIsPresent : True | |
# CleganeBowlBound : True | |
# KingsMoot : False | |
# KingsMootIsPresent : False | |
# KingsMootBound : True | |
$Parameters = @{ | |
CleganeBowl = $true | |
} | |
Get-Hype @Parameters | |
# CleganeBowl : True | |
# CleganeBowlIsPresent : True | |
# CleganeBowlBound : True | |
# KingsMoot : False | |
# KingsMootIsPresent : False | |
# KingsMootBound : False | |
# Actually these last two examples technically do detect, but I can't see a use case, especially in relation to the linked reddit question |
This file contains hidden or 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
function Get-Hype { | |
param ( | |
$CleganeBowl = $false, | |
$KingsMoot = $false | |
) | |
New-Object psobject -Property ([ordered]@{ | |
CleganeBowl = $CleganeBowl | |
CleganeBowlBound = $PSBoundParameters.ContainsKey('CleganeBowl') | |
KingsMoot = $KingsMoot | |
KingsMootBound = $PSBoundParameters.ContainsKey('KingsMoot') | |
}) | |
} | |
Get-Hype | Format-List | |
# CleganeBowl : False | |
# CleganeBowlBound : False | |
# KingsMoot : False | |
# KingsMootBound : False | |
Get-Hype -CleganeBowl $true | Format-List | |
# CleganeBowl : True | |
# CleganeBowlBound : True | |
# KingsMoot : False | |
# KingsMootBound : False | |
Get-Hype -CleganeBowl $true -KingsMoot $false | Format-List | |
# CleganeBowl : True | |
# CleganeBowlBound : True | |
# KingsMoot : False | |
# KingsMootBound : True | |
$Parameters = @{ | |
CleganeBowl = $true | |
KingsMoot = $false | |
} | |
Get-Hype @Parameters | Format-List | |
# CleganeBowl : True | |
# CleganeBowlBound : True | |
# KingsMoot : False | |
# KingsMootBound : True | |
$Parameters = @{ | |
CleganeBowl = $true | |
} | |
Get-Hype @Parameters | Format-List | |
# CleganeBowl : True | |
# CleganeBowlBound : True | |
# KingsMoot : False | |
# KingsMootBound : False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment