Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Friday, August 23, 2019 9:32 AM
Hi Everyone,
Age old issue, we have comma's in users "NAME" field in AD, and its causing problems with LDAP look-ups.
I have the PS to rename the "NAME" field, to match the "Display Name" field as below:
Get-ADUser -Filter * -SearchBase "OU=CN Name Test,OU=Test Accounts,OU=Users,OU=AD,DC=Contoso,DC=net" -Properties DisplayName | foreach {Rename-ADObject -Identity $_.DistinguishedName -NewName $_.DisplayName -PassThru}
I would like the script to refer to a CSV though, rather than an OU as above. I have a CSV with the Username and Display Name fields extracted, but unsure how to get the above to refer to that rather than a specific OU.
Any assistance greatly appreciated!
All replies (2)
Friday, August 23, 2019 10:11 AM âś…Answered
Hi,
Thanks for your question.
You can use powershell "import-csv" cmdlet to import csv and foreach-object cmdlet to loop execute rename ad object.
Csv example:
powershell script example:
Import-Csv -Path "c:\test\infor.csv" |ForEach-Object { Rename-ADObject -Identity $_.DistinguishedName -NewName $_.Displayname -Confirm:$false}
Best regards,
Lee
Just do it.
Friday, August 23, 2019 11:03 AM
Hi,
agree with Lee om that, you just need to be carefull how exactly the user names are stored inm the CSV file - "username" or CN= Username, OU=xxxxxx (DN format).
Besides this, import-csv is your friend. Here also a couople of articles with examples of this, which you can simply adjust to your case:
PowerShell Import-CSV Cmdlet: Parse a Comma-Delimited CSV Text File
PowerShell and Your Data Made Easy
Processing CSV data in PowerShell
Just make sure you have tested you script good before running it production.
Regards,
(Please take a moment to "Vote as Helpful" and/or "Mark as Answer" where applicable. This helps the community, keeps the forums tidy, and recognizes useful contributions. Thanks!) Blog: https://blog.pohn.ch/ Twitter: @StoyanChalakov