Can someone tell me why this pipeline implementation doesn’t work?
function count
{
[CmdletBinding()]
Param
(
[Parameter(ValueFromPipelineByPropertyName=$true)]
[Alias('Name')]
[string[]]
$ComputerName
)
Begin
{ Write-Host "Computer count: $($ComputerName.count)" }
Process { }
End { }
}
The variable is null as in it’s not getting any data from the pipeline.
PS > Get-ADComputer -filter * | count Computer count: 0 PS > (Get-ADComputer -filter *).count 117
The property name is Name, matches the alias I added above.
PS > Get-ADComputer -filter * |gm
TypeName: Microsoft.ActiveDirectory.Management.ADComputer
Name MemberType Definition
---- ---------- ----------
Contains Method bool Contains(string propertyName)
Equals Method bool Equals(System.Object obj)
GetEnumerator Method System.Collections.IDictionaryEnumerator GetEnumerator()
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
Item ParameterizedProperty Microsoft.ActiveDirectory.Management.ADPropertyValueCollection Item(string propertyName) {get;}
DistinguishedName Property System.String DistinguishedName {get;set;}
DNSHostName Property System.String DNSHostName {get;set;}
Enabled Property System.Boolean Enabled {get;set;}
Name Property System.String Name {get;}
ObjectClass Property System.String ObjectClass {get;set;}
ObjectGUID Property System.Nullable`1[[System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] ObjectGUID {get;set;}
SamAccountName Property System.String SamAccountName {get;set;}
SID Property System.Security.Principal.SecurityIdentifier SID {get;set;}
UserPrincipalName Property System.String UserPrincipalName {get;set;}