It is still showing the entire line instead of truncating it…
In any case I think the formatting I chose might have been wrong in this context…I was wondering whether there was any other way that I can format it to format the distinguished name property.
OUs can be rather long, and Format-Table will truncate things to fit your console window if it needs to. (Format-Table is being used behind the scenes here.)
If you don’t care about the table format, try just piping to Format-List instead.
I was curious about this as you quoted my blog post so I tried your code
what I’m seeing under the Organisational Unit out put is lines like this
{(CN=Dave Greenly,OU=Testing,DC=Manticore,DC=org.DistinguishedName -split ,…
In other words its showing you what its trying to do rather than the result.
The reason is that there’s an error in your select statement - specifically the calculated field
@{N= “Organanisational Unit” ; E = {(“($_.DistinguishedName -split “,”,2)[1])”)}}
Your expression is effectively outputting 2 strings
"($_.DistinguishedName -split " which will substitute the value for the distinguished name
and
“,2)[1])” which outputs what you see.
The correct syntax is
Get-ADUser -Filter * -Properties DisplayName | select DisplayName, UserPrincipalname, @{N= “Organanisational Unit” ;
E = {($_.DistinguishedName -split ‘,’, 2)[1]}}
BTW you don’t need to put userprincipalname and distinguishedname in the -Properties list as those are default properties that are always shown. -Properties is for properties you want in addition to the default
You should see the OU in the format you want now. if the output is still too long use format-list as mentioned by Dave or Format-table -wrap