Hi, so as part of a script I am running against AD, I request the management field from user properties. All information that I am requesting looks fine, except for the manager field. Here is the section of script and what is returned:
[pre]Get-ADUser $UserID -Properties *| select displayname, department, description, manager, office, officephone, emailaddress[/pre]
And the output is:
> Active Directory User Information
displayname : Displayed Name
department : Bla Bla Region
description : Staff
manager : CN=Mr Manager,OU=Windows 7,OU=UserAccounts,OU=xxx,OU=xxx,DC=xxx,DC=net
office : xxx
officephone : +xxxxxxxxx
emailaddress : email.address@email.com
But i'd like to supress some of the manager field to only show:
[pre]manager : Mr Manager[/pre]
Thanks in advance
'CN=Mr Manager,OU=Windows 7,OU=UserAccounts,OU=xxx,OU=xxx,DC=xxx,DC=net'.Split(',')[0].Split('=')[1]
Get-ADUser $UserID -Properties * |
select displayname, department, description, @{n='ManagerName';e={$_.manager.Split(',')[0].Split('=')[1]}}, office, officephone, emailaddress
Olaf
March 21, 2019, 7:56am
3
Get-ADUser $UserID -Properties displayname, department, description, office, officephone, emailaddress, Manager |
Select-Object -Property displayname, department, description, office, officephone, emailaddress, @{Name = 'Manager'; Expression = {(($_.manager -split ',')[0] -split '=')[1]}}
Thanks everyone, Olaf - worked straight away, I just need to learn why now!
[pre]Expression = {(($_.manager -split ‘,’)[0] -split ‘=’)[1]}}[/pre]
So you split the results with “,” as the split leaving “CN=Mr Manager”, and then split again with “=” and the “[1]” displays the second split there?
Nice! - thanks