Link to home
Start Free TrialLog in
Avatar of amir damirov
amir damirov

asked on

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.
Avatar of footech
footech
Flag of United States of America image

You would have to provide your script to troubleshoot.
Just based on reading what your experiencing I'd say your script needs to assign the displayname based on the Firstname csv value.
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
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
Avatar of amir damirov
amir damirov

ASKER

Dear All, thank you for the replies. Here is my script

User generated image
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.
User generated image
Do a set after
Set-ADUser ($User) -Replace @{ "cn" = "$($User.DisplayName)"}

Open in new window

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.User generated image
Hi Amir

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

User generated image
SOLUTION
Avatar of footech
footech
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Please post the whole script as is
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
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Dear All, thank you for your response.