Powershell export all missing displaynames in AD and set them.


Powershell coding:

I would like to first export all the users in AD that missing a displayname to a excel csv.
Then edit all the displaynames to the users that miss the displayname in that excel file.
Then use get-content to set-aduser to those displayname with the right account.

Anyway to do this?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

WeTiAuthor Commented:
The import csv is done as below tho, how to export?
Import-Csv user.csv | Foreach {Get-ADUser -Identity $_.sAMAccountname | Set-ADUser -DisplayName $_.DisplayName}
WeTiAuthor Commented:
like this?
Get-ADUser -Filter { displayName -notlike '*' } | Select-Object Samaccountname | Export-Csv user.csv
here is how I would do it and then just create a foreach loop to include the importcsv command above.

$adinfocollection = get-aduser -property Displayname -filter * |Select Name, Displayname
$NullObjects = $adinfocollection |? {$_.displayname.psobject.properties.value -like "$($null)"}

$nullobject |export-csv -NoTypeInformation -path c:\output.csv

Open in new window

Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

WeTiAuthor Commented:
this: Import-Csv user.csv | Foreach {Get-ADUser -Identity $_.sAMAccountname | Set-ADUser -DisplayName $_.DisplayName}
Checks samaccountname and then set displayname.
Your output.csv got no samAccountname? you only select the Name and displayname, what is the whole code together?
missed that you needed the samaccount name
$adinfocollection = get-aduser -property Displayname -filter * |Select Name, Displayname, samaccoutname

Open in new window

I will be at a computer where I can test in about 10 minutes at the moment I can't test the code I am providing.
This gets the null values for you.

$adinfocollection = get-aduser -property Displayname -filter * |Select Name, Displayname, samaccountname
$Nullobjects = $adinfocollection |? {$_.displayname.psobject.properties.value -like "$($null)"}
$nullobjects |export-csv -NoTypeInformation -path c:\output.csv

Open in new window

Make your modifications

Can't test your import at the moment, but if your syntax is right :

Import-Csv output.csv | Foreach {Get-ADUser -Identity $_.samaccountname | Set-ADUser -DisplayName $_.DisplayName}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
please let me know the results of your test when you get a moment.
WeTiAuthor Commented:
Working thanks alot
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.