Link to home
Create AccountLog in
Avatar of cawasaki
cawasaki

asked on

powershell script to get all AD user without displayname

hello,

i need a powershell script to get all AD user without displayname and export them to a csv file.

the script must get the user from specific OU.

after that, i need to use the csv file with user to set a displayname like that:
displayname =  SN + Givenname

thanks for help
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

This should do it.
Get-ADUser -Filter { displayName -notlike '*' } -SearchBase "OU=somewhere,DC=domain,DC=local" |
    Select-Object Name, FirstName, LastName, DisplayName, DistinguishedName | 
    Export-Csv file.csv

Open in new window

I think all of the properties I've asked for are returned by default. If any are inexplicably blank the property will need requested. For example:
Get-ADUser -Filter { displayName -notlike '*' } -SearchBase "OU=somewhere,DC=domain,DC=local" -Properties canonicalName |
    Select-Object Name, FirstName, LastName, DisplayName, DistinguishedName | 
    Export-Csv file.csv

Open in new window

DistinguishedName is included because it makes pushing changes back in again afterwards a very definite process.
Avatar of cawasaki
cawasaki

ASKER

hello,

the script get the account, but
for lastname and firstname i have :

Microsoft.ActiveDirectory.Management.ADPropertyValueCollection

and i need the script to:

after that, i need to use the csv file with user to set a displayname like that:
displayname =  SN + Givenname
ASKER CERTIFIED SOLUTION
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
thank you Chris :)