Nikita Levitan Nikita Levitan - 4 months ago 30
PowerShell Question

Powershell to split Display name and use it to populate First Last name

Need some help with my code. I have users in OU, they have Display Name attribute but First/Last name are empty. I am trying to populate them using powershell. here is what i got so far:

get-aduser -filter * -SearchBase 'OU=FTE,OU=GLS,OU=Staff,DC=domain,DC=com’ | % {$ –split " "}

This gives me the output for John Doe as


now i am trying to set these values using this, but it fails:

$SplitName = $ –split " "

get-aduser -filter * -SearchBase 'OU=FTE,OU=GLS,OU=Staff,DC=domain,DC=com’ | % {Set-ADUser -Identity $_ -GivenName $SplitName[0] -Surname $SplitName[1]}

I think i am not using the split correctly, but I am not sure.


Without AD with me, I don't see why this wouldn't work:

get-aduser -filter * -SearchBase 'OU=FTE,OU=GLS,OU=Staff,DC=domain,DC=com’ | % {
       $splitName = $ –split " "
       Set-ADUser -Identity $_ -GivenName $SplitName[0] -Surname $SplitName[1]