Consider the following code:
function Test
{
[CmdletBinding()]
param
(
[parameter(Mandatory=$true)]
[AllowNull()]
[String]
$ComputerName
)
process{}
}
Test -ComputerName $null
Based on the official documentation for AllowNull
I was expecting that $ComputerName
could either be [string]
or $null
. However, running the above code results in the following error:
[14,24: Test] Cannot bind argument to parameter 'ComputerName' because it is an empty string.
Why doesn't passing $null for $ComputerName
work in this case?