Function Alias Question

I am unsure why something like this does not work:

I have a function e.g.:

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

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

Load this function, and then try:

get-aduser "name" | get-name

This returns nothing.
Change the Parameter var to $samaccountname it then returns the samaccountname (from the pipeline).
I thought have the alias there should allow it to return that value from the pipeline?
Just wondering if this is something that I have misunderstood?

Welcome to the “People annoyed by the ActiveDirectory” module club. I’m not only the president, I’m also a member! :slight_smile:

Seriously, this would work with literally any other command piped to your function except those in the AD module. Those objects are just weird, but there is a workaround:

get-aduser "name" | select * |  get-name

It looks silly to stick “select *” in the pipeline like that, but it produces an object that is much better behaved than the original.

Aaahhhh, this would explain a lot - I thought I was loosing my mind.

I am glad you cleared this up, I can now give my head a rest from banging it off the desk.

Much appreciated Dave :slight_smile: