Reputation: 33
Hello I'm currently trying to have my Get-ADUser expression to sort the Manager to just display the managers name. I have search for multiple solutions however nothing that matches what I've been trying to do with have all my properties listed as shown.
Get-ADUser $username -Properties Enabled,employeeNumber,DisplayName,Mail,Description,office,extensionAttribute1,manager,AccountExpirationDate |
Select-Object Enabled,
@{Expression={$_.DisplayName};Label='Display Name';},
@{Expression={$_.Mail};Label='Email';},
@{Expression={$_.employeeNumber};Label='Employee Number'},
@{Expression={$_.AccountExpirationDate};Label='Account Expiration Date'},
@{Expression={$_.Description};Label='Account Description'},
Office,
@{Expression={$_.extensionAttribute1};Label='Cost Center';},
Manager
Format-list
Currently the output is:
Manager: CN=Billy Bob Manager,OU=Users,OU=MAHRS,OU=Locations,OU=Test,DC=corp,DC=TestDC,DC=com
I would like to know how I could keep everything under the original Get-ADUser.
Thanks!
Upvotes: 2
Views: 439
Reputation: 60563
You have 2 simple options, either query AD for the Manager's .Name
attribute:
@{ Expression = { (Get-ADUser $_.Manager).Name }; Label = 'Manager' }
Or extract the cn
from the DistinguishedName with regex:
@{ Expression = { $_.Manager -replace '^CN=|(?<!\\),.+' }; Label = 'Manager' }
Relevant documentations:
Select-Object
Select-Object
from about Calculated PropertiesUpvotes: 3
Reputation: 22281
No, it is not possible with Active Directory to do a "join" in a single LDAP query. It is possible with other LDAP directories (OpenLDAP) using the dereference control.
Upvotes: 0