Why alias does not work?

Welcome Forums General PowerShell Q&A Why alias does not work?

This topic contains 2 replies, has 2 voices, and was last updated by

3 years, 8 months ago.

  • Author
  • #22530
    X P

    Points: 0
    Rank: Member

    Hi Everyone! Thanks at first!

    I have an Issue, I don't understand this behavior.

    My Function Get-Test2 tell me the Manufacture, examples:

    PS C:\> Get-Test2

    Computername Manufacturer
    ———— ———— Dell Inc.

    It's OK, this is what I want

    PS C:\> "" | Get-Test2 

    Computername Manufacturer
    ———— ———— Dell Inc.

    It's OK

    But, from the Pipeline Of a Get-adcomputer command.

    PS C:\> Get-ADComputer test | Get-Test2 

    Computername Manufacturer
    ———— ————
    CN=test,CN=Computers,DC=R,DC=LAN Dell Inc.

    I get

    DistinguishedName : CN=SI,CN=Computers,DC=R,DC=LAN,, I don't want DistinguishedName, I want DNSHostname

    I put an alias, but appears It doesn't work.

    This is my Psrameter:


    Can anyone explain me this behavior?


  • #22535

    Points: 0
    Rank: Member

    In short, the AD cmdlets are weird, and don't always play well with being piped directly into other commands. (Particularly those that use aliases.)

    Any easy workaround is to stick a call to Select-Object in the middle:

    Get-ADComputer test | Select-Object -Property * | Get-Test2

    It looks weird, but it works. Select-Object converts the objects that the AD cmdlet outputs into simple PSObjects with the same properties / values, and those PSObjects work fine when piped into other functions.

  • #22536
    X P

    Points: 0
    Rank: Member

    You are right! It WORKS! But looks weird.


The topic ‘Why alias does not work?’ is closed to new replies.