Basically, the scenario is user is providing a CSV. We’ll say there are two params First and Second. If the user does not provide a Second param in the CSV, the goal is to use the default function param. So, the function:
Function Test-It{
Param(
[Parameter(Mandatory=$false,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True,
HelpMessage=‘The first parameter’)]
[AllowNull()]
[AllowEmptyString()]
[string]$First =“FirstDefault”,
[Parameter(Mandatory=$True,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True,
HelpMessage=‘The second parameter’)]
[AllowNull()]
[AllowEmptyString()]
[string]$Second =“SecondDefault” )
begin{}
process{
Write-Host ("First: {0}" -f $First)
Write-Host ("Second: {0}" -f $Second)
}
end{}
}
If I do Test-It -First “Whatever”, the default works correctly. If I pass both params over the pipeline:
$parameters = New-Object -TypeName PSObject -Property @{
First = “Hello”
Second = “Rob”
}
Clear-Host
$parameters | Test-It
Returns:
First: Hello
Second: Rob
But if I only pass one parameter over the pipeline:
$parameters = New-Object -TypeName PSObject -Property @{
First = “Hello”
}
Clear-Host
$parameters | Test-It
Then it returns like this when I expect Second: SecondDefault:
First: Hello
Second: @{First=Hello}
How do input default params are utilizing when using the pipeline?