Author Posts

March 4, 2016 at 1:55 pm

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}}

March 4, 2016 at 2:09 pm

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.

March 4, 2016 at 7:17 pm

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.

March 4, 2016 at 8:05 pm

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


March 9, 2016 at 1:37 pm

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}}