Last active
August 29, 2015 14:19
-
-
Save ChaseFlorell/9e12f8f80711baa2150a to your computer and use it in GitHub Desktop.
A slick way to do overloads in powershell.
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
function Get-FullName { | |
param( | |
[parameter(position=0, parametersetname="a")] [string] $firstName, | |
[parameter(position=1, parametersetname="a")] [string] $lastName, | |
[parameter(position=0, parametersetname="b")] [hashtable] $name | |
) | |
if($PSCmdlet.ParameterSetName -eq 'b') { | |
# Doing recursion will allow for parameter validation if need be! | |
Get-FullName $name.first $name.last | |
return | |
} | |
"{0} {1}" -f $firstName, $lastName | |
} | |
Get-FullName "john" "doe" | |
Get-FullName @{'first'='bob'; 'last'='smith'} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment