Consider the following function:
function f1{
param(
$sb = {},
$s = ''
)
if ($sb -isnot [scriptblock]) { 'scriptblock' }
if ($s -isnot [string] ) { 'string' }
}
Now invoke it with a splat parameter:
PS C:\> $splat = @{foo='bar'}
PS C:\> f1 @splat
As expected, nothing is returned. Now try it again with a $null
splat parameter:
PS C:\> $splat = $null
PS C:\> f1 @splat
scriptblock
Oddly, scriptblock
is returned. Clearly, at least for the [scriptblock]
parameter, powershell is not honoring the default value when a $null
splat parameter is used. But powershell does honor the default value for the [string]
. What is going on here?
For what types does Powershell honour default values when using $null splat parameters?