Forum Discussion
dding0919
Nov 21, 2024Copper Contributor
Not able to export AD attribute departmentnumber
Hi, I'm trying to generate a report for all AD users with some AD attributes, such as SamAcconutName, department, departmentnumber, etc. The report is fine with all except departmentnumber. it sho...
LainRobertson
Nov 21, 2024Silver Contributor
Hi dding0919 ,
This is expected for any multivalued attribute.
What you can do is leverage the functionality within Select-Object for creating a custom property on-the-fly to action a join on the multivalued departmentNumber attribute, as demonstrated below.
Command
Get-ADObject -Filter { (userPrincipalName -eq "email address removed for privacy reasons") } -Properties displayName, departmentNumber | Select-Object -Property displayName, @{ n="departmentNumber"; e = { $_.departmentNumber -join ","; } };
Output
If you were pulling numerous multivalued attributes, I'd likely switch strategies to using a ForEach-Object construct in lieu of Select-Object as it's more readable, but for a single multivalued attribute, there's no need.
Cheers,
Lain