ps/Modules/Cole.PowerShell.Developer/Public/Test-SplatUsage.ps1
2023-05-30 22:51:22 -07:00

119 lines
2.5 KiB
PowerShell

function Test-SplatUsage {
<#
.SYNOPSIS
This function demonstrates how splats work based on what is passed in.
.EXAMPLE
This example will error for too many values being supplied:
(Parses Param2 before Param1)
$splat = @{
Param1 = "Lorem"
Param2 = "ipsum"
Param3 = "dolor"
Param4 = "sit"
Param5 = "amet"
}
Test-SplatUsage -Param1 "thing" -Param2 "other thing" @splat
.EXAMPLE
This example will error for too many values being supplied:
(Parses Param2 before Param1)
$splat = @{
Param1 = "Lorem"
Param2 = "ipsum"
Param3 = "dolor"
Param4 = "sit"
Param5 = "amet"
}
Test-SplatUsage -Param2 "thing" -Param1 "other thing" @splat
.EXAMPLE
This example will do what you want:
$splat = @{
Param3 = "dolor"
Param4 = "sit"
Param5 = "amet"
}
Test-SplatUsage -Param1 "thing" -Param2 "other thing" @splat
.EXAMPLE
Can I double-splat? Why yes, yes I can!
$splat = @{
Param3 = "dolor"
Param4 = "sit"
Param5 = "amet"
}
$splat2 = @{
Param1 = "Lorem"
Param2 = "ipsum"
}
Test-SplatUsage @splat @splat2
.EXAMPLE
Alpha ordering test on failure conditions (test 1)
$splat = @{
Param1 = "Lorem"
Param2 = "ipsum"
Param3 = "dolor"
Param4 = "sit"
Param5 = "amet"
alphaTest = "wrong"
ALPHACAPS = "again wrong"
}
Test-SplatUsage -Param2 "thing" -alphacaps "wrong case" -alphaTest "supplied" -Param1 "other thing" @splat
.EXAMPLE
Alpha ordering test on failure conditions (swapped case)
$splat = @{
Param1 = "Lorem"
Param2 = "ipsum"
Param3 = "dolor"
Param4 = "sit"
Param5 = "amet"
alphaTest = "wrong"
ALPHACAPS = "again wrong"
}
Test-SplatUsage -Param2 "thing" -ALPHACAPS "wrong case" -alphaTest "supplied" -Param1 "other thing" @splat
.EXAMPLE
Alpha ordering test on failure conditions (swapped params order)
$splat = @{
Param1 = "Lorem"
Param2 = "ipsum"
Param3 = "dolor"
Param4 = "sit"
Param5 = "amet"
alphaTest = "wrong"
ALPHACAPS = "again wrong"
}
Test-SplatUsage -Param2 "thing" -alphaTest "supplied" -ALPHACAPS "wrong case" -Param1 "other thing" @splat
#>
param (
$param1,
$param2,
$param3,
$param4,
$param5,
$param6,
$alphaTest,
$ALPHACAPS
)
Write-Host (ConvertTo-Json @{
Param1 = $param1
Param2 = $param2
Param3 = $param3
Param4 = $param4
Param5 = $param5
Param6 = $param6
alphaTest = $alphaTest
ALPHACAPS = $ALPHACAPS
})
}