Active Directory powershell script Display Name issue

Hi Everyone. I have a script which provides me to create bulk of users. Script reads my csv file and fills attributes from this csv. But I have an issue. Display name shows not correct in my AD interface. When I create manually from AD interface it seems ok.
As you see from image user:spashaeyv have displayname but in AD interface it doesn't show it. It shows direct username. How can I solve this issue?

But user Delicatessen which I have created manual seems ok.
amir damirovAsked:
Who is Participating?
 
footechCommented:
Where's the issue?  Using your example shows the display name fine for me.
 sample userDo you see something different?

If you're talking about what's displayed in the red box, if you want that to be the same as the Display Name, then you need to change what you supply to the -Name parameter for New-ADUser.  Like
New-ADUser -Name $User.DisplayName
0
 
footechCommented:
You would have to provide your script to troubleshoot.
0
 
J SSenior Systems AdministratorCommented:
Just based on reading what your experiencing I'd say your script needs to assign the displayname based on the Firstname csv value.
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

 
J SSenior Systems AdministratorCommented:
Another thought is if that doesnt work, is to create your users, then run an additional set-aduser -displayname either after create or in another loop
0
 
Shaun VermaakTechnical Specialist/DeveloperCommented:
That is not the display name, that is the cn. Change script to set the same value to the cn that is assigned to display name
1
 
amir damirovAuthor Commented:
Dear All, thank you for the replies. Here is my script

bulk-of-users.JPG
Dear Shaun,

I've tried to assign value to the "cn" as you wrote. But for the "New-ADuser" command there is no such key "cn". I couldnt find it.
cn.JPG
0
 
Shaun VermaakTechnical Specialist/DeveloperCommented:
Do a set after
Set-ADUser ($User) -Replace @{ "cn" = "$($User.DisplayName)"}

Open in new window

0
 
amir damirovAuthor Commented:
Dear Shaun, thank you for reply.

This is my first script expierence in povvershell. Think there is something wrong again. Becasuse i've ran that comman it shows error.script.JPG
0
 
Shaun VermaakTechnical Specialist/DeveloperCommented:
Hi Amir

That needs to run within the loop. So in line 19, before the } and a ; and the line I posted
0
 
amir damirovAuthor Commented:
Hi again and thanks for your help, Shaun. I've tried but the same error ;\

scriptJPG.JPG
0
 
footechCommented:
What happened to the images in the original question?  With those missing, it makes it much more difficult to see what your issue is.

Sorry to have to contradict the others, but there's no need to set the cn attribute specifically.  I have a script which I use regularly to create users, and it has no such thing.  The cn attribute is populated when you supply information to the -Name parameter of New-ADUser.  If you try to change it with Set-ADUser, you will get an error that says, "The attribute cannot be modified because it is owned by the system".

The script as shown in #a42509183 will not work.  (Side note - it's always best to provide your code as text within a code block, rather than an image, so that others can easily copy it and test).  The code as shown will display errors because of the way you've broken up the (single) command into multiple lines without using a line continuation character.  If I fix it to run without error, then the DisplayName is filled correctly.

Provide your images again, and a sample input .CSV with which you can duplicate what you are seeing.  It's possible there's a format issue with your .CSV that's causing the issue.
0
 
Shaun VermaakTechnical Specialist/DeveloperCommented:
Please post the whole script as is
0
 
amir damirovAuthor Commented:
Thank you, again.  Here is my code below. There is no issue with CSV file. Because below code works fine.

So I need just correct display name for users.

I can provide CSV file, too.

$Password = Read-Host "Enter the password that you want to set" -AsSecureString

$Users= Import-Csv 'C:\Bulk of users.csv'


$users | ForEach-Object {mkdir($_.’HomeDirectory’)}


foreach($User in $Users){New-ADUser -Name $User.LoginName -Title $user.Title -PostalCode $user.Postal -Country $User.Country -office $User.office -city $User.city -Surname $User.LastName -State $User.State -GivenName $User.Firstname -SamAccountName $User.LoginName -userPrincipalName $User.PrincipalName -Department $User.Department -Company $User.Company -AccountPassword $Password -DisplayName $User.DisplayName -HomeDirectory $User.HomeDirectory -HomeDrive $User.HomeDrive -Path "OU=Users,OU=1000,OU=Markets A, DC=firstit, DC=az" -Enabled $true -Passthru }

Open in new window

Bulk-of-users.csv
0
 
amir damirovAuthor Commented:
Dear All, thank you for your response.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.