# Parameter alias not working in pipeline

**URL:** <https://forums.powershell.org/t/parameter-alias-not-working-in-pipeline/5344>\
**Category:** PowerShell Help\
**Created:** [December 10, 2015, 1:48am UTC](https://forums.powershell.org/t/parameter-alias-not-working-in-pipeline/5344 "2015-12-10T01:48:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![erik-sundin](https://avatars.discourse-cdn.com/v4/letter/e/f0a364/32.png) [@erik-sundin](https://forums.powershell.org/u/erik-sundin)\
**Post date:** [December 10, 2015, 1:48am UTC](https://forums.powershell.org/t/parameter-alias-not-working-in-pipeline/5344/1 "2015-12-10T01:48:07Z")

</div>

Hello,

I´m fairly new to scripting/programming in general (including Powershell), trying to move away from being a GUI-based technician. While doing my best to get my first cmdlets to work I came across an unexpected behavior, I hope someone can give me an explanation for this. I made two nearly identical functions to illustrate my problem:

```auto
 function Test-Name
{    
    Param
    (
        [Parameter(ValueFromPipelineByPropertyName=$true, Mandatory=$true)]
        [Alias("Name")] 
        $ComputerName
    )

    $ComputerName
}

function Test-Name2
{    
    Param
    (
        [Parameter(ValueFromPipelineByPropertyName=$true, Mandatory=$true)]
        [Alias("ComputerName")] 
        $Name
    )

    $Name
}  

```

And then I tested a few things:

PS U:&gt; Get-ADComputer Test | Test-Name  
Test-Name : Cannot bind argument to parameter ‘ComputerName’ because it is null.  
At line:1 char:23

- Get-ADComputer Test | Test-Name
- 

```
                  ~~~~~~~~~

```

  - CategoryInfo : InvalidData: (CN=Test,CN=Computers,DC=test,DC=ing:PSObject) [Test-Name], ParameterBindingValidationException
  - FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Test-Name

PS U:&gt; Get-ADComputer Test | Select-Object Name | Test-Name  
Test

PS U:&gt; Get-ADComputer Test | Test-Name2  
Test

PS U:&gt; (Get-ADComputer Test).gettype()

IsPublic IsSerial Name BaseType

* * *

True False ADComputer Microsoft.ActiveDirectory.Management.ADAccount

PS U:&gt; (Get-ADComputer Test | Select-Object \*).gettype()

IsPublic IsSerial Name BaseType

* * *

True False PSCustomObject System.Object

I red in a post, that I unfortunately can´t find right now, that objects from ActiveDirectory module cmdlets acts weird in the pipeline and that using Select-Object was a way around it. I can see that the object types are different, but why does it work when the parameter name match the property name from the pipeline?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [December 10, 2015, 2:02am UTC](https://forums.powershell.org/t/parameter-alias-not-working-in-pipeline/5344/2 "2015-12-10T02:02:30Z")

</div>

Meet the ActiveDirectory module, one of the most annoying things ever produced for PowerShell. 🙂 The objects that come out of those commands behave very oddly. As you mentioned, piping the AD commands to “Select-Object \*” first is a viable workaround, because it changes the type of the objects that you’re piping into other functions.

The reason for this is that the AD objects, when you try to _read_ any property, will automatically create a property on themselves of that name with no value. (They’re essentially both an object and a hashtable, in terms of their interface). When you pipe in an object to your function with an aliased parameter, this is what would normally happen:

- PowerShell checks the object for a property matching the actual parameter name “ComputerName”
- That’s not found, so instead it starts checking the aliases. It finds a property “Name”, and binds that.

But when you’re using these goofy AD objects, instead it goes like this:

- PowerShell checks the object for a property of type ComputerName. It didn’t exist before this happened, but now suddenly the object has a “ComputerName” property with no value. PowerShell binds this to your parameter, and never bothers checking the aliases.

---

<div class="post-metadata">

**Author:** ![erik-sundin](https://avatars.discourse-cdn.com/v4/letter/e/f0a364/32.png) [@erik-sundin](https://forums.powershell.org/u/erik-sundin)\
**Post date:** [December 10, 2015, 2:45am UTC](https://forums.powershell.org/t/parameter-alias-not-working-in-pipeline/5344/3 "2015-12-10T02:45:14Z")

</div>

Thank you for your time and thorough explanation, my mind is at ease once again 🙂

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:44pm UTC](https://forums.powershell.org/t/parameter-alias-not-working-in-pipeline/5344/4 "2024-05-16T20:44:20Z")

</div>


