Skip to content

Instantly share code, notes, and snippets.

@ChaseFlorell
Last active August 29, 2015 14:19
Show Gist options
  • Save ChaseFlorell/9e12f8f80711baa2150a to your computer and use it in GitHub Desktop.
Save ChaseFlorell/9e12f8f80711baa2150a to your computer and use it in GitHub Desktop.
A slick way to do overloads in powershell.
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