I recently found something out (with much appreciated help over at http://powershell.org and Dave Wyatt).

I have been writing some PowerShell functions that will accept pipeline values from Active Directory object. Lets just take a basic function to give you an example.

function get-name
{
    [CmdletBinding()]
    Param
    (
        # Param1 help description
        [Parameter(Mandatory=$true,
                   ValueFromPipelineByPropertyName=$true,
                   Position=0)]
        [alias("SamAccountName")]
        $myname
    )

    Begin
    {
    }
    Process
    {
    }
    End
    {
        echo $myname
    }
}

Very very basic function to show my issue.

So this function should be able to accept a pipeline value by property name and because there is an alias specified - “SamAccountName” it should be able to use this too.

So in theory, this:

Get-Aduser "Alex.Innes" | Get-Name

should work…Yes?

No!

Returns nothing in the console:

Output 1

I spend too long looking into this issue before reaching out to the PowerShell community, to see where I was going wrong in my script.

Thankfully, within 10 minutes Dave and I was happy to find out this is not something that I was doign wrong but an oddity within the Active Directory module. The solution to this issue:

Output 2

Yes, adding a “select *” in the pipline fixes the issue. Odd, yes - but if it works…. I had this issue with AD Computers objects too, so I am assuming its with all Active Directoy objects.

So hopefully if you have this issue, you might not spend as long banging your head off the desk and find this solution.