When objects are piped in, BEGIN{} runs first, before any objects are piped in. You’re correctly displaying zero. PROCESS{} is then given one object at a time - it will never be more than 1. Then, END{} runs. There’s no way, within an advanced function, to know how many objects are coming down the pipeline, because they’re fed in singly.
Bad example on my part. Same null issue when I put it in the process block.
My actual function doesn’t count, just using that to keep my example simple and demonstrate the issue. It’s an alias problem. As far as I can tell, the alias is implemented correctly.
function count
{
[CmdletBinding()]
Param
(
[Parameter(ValueFromPipelineByPropertyName=$true)]
[Alias('Name')]
[string[]]
$ComputerName
)
Begin { }
Process
{ Write-Host "Computer count: $($ComputerName.count)" }
End { }
}
I can confirm it a issue with the object returned from get-ADComputer. At some point I had a good detailed explanation of the issue with the AD cmdlets but it escapes me at the moment.
You can use the your original code if you select the attributes you want before piping to your function