Help with get-aduser pipeline

This topic contains 4 replies, has 3 voices, and was last updated by Profile photo of jrcochranusa jrcochranusa 6 months, 3 weeks ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #36093
    Profile photo of jrcochranusa
    jrcochranusa
    Participant

    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
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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
    Profile photo of Jeremy Murrah
    Jeremy Murrah
    Participant

    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
    Profile photo of jrcochranusa
    jrcochranusa
    Participant

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

    ~jrc

    #36338
    Profile photo of jrcochranusa
    jrcochranusa
    Participant

    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 mydomain.com | select @{n='manager';e={(get-qaduser -Properties mailnickName $_.manager).mailNickName}}

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.