Help with get-aduser pipeline

This topic contains 4 replies, has 3 voices, and was last updated by  jrcochranusa 2 years, 4 months ago.

  • Author
  • #36093


    This works fine when the manager is in the same domain as the user, but what if I don't know what domain the manager will be in?

    Get-ADUser $user -Properties manager | select samAccountName,@{n='manager';e={(get-aduser -Properties mailnickName $_.manager).mailNickName}}

  • #36095

    Don Jones

    Not a whole bunch you can do about that, if you flat-out don't know what domain they're in at the time. You need to be able to tell the command what domain to query.

  • #36113

    Jeremy Murrah

    The manager field output should be a distinguished name, so you could do some string manipulation to get the domain from there. For ease of use I'd write a function called get-domainfromDn. Then your select scriptblock could be

     {get-aduser -properties mail nickname -identity $_.manager - server $(get-domainfromDn $_.manager) } 

    Assuming your credentials are good for the other domain it should work.

  • #36114


    Good idea... I'll give that a whirl!


  • #36338


    Easier solution and I hate to do it because I prefer to stay native, but I have other work to do! The Quest snap-in recognizes the domain of the object for which the property you are trying to retrieve.

    get-qaduser testmtwain -service | select @{n='manager';e={(get-qaduser -Properties mailnickName $_.manager).mailNickName}}

You must be logged in to reply to this topic.