HOW TO IMPORT / EXPORT ActiveDirectory User List with Properties (French Characters – UTF8)

HOW TO IMPORT / EXPORT ActiveDirectory User List with Properties (French Characters – UTF8)
1- Export Users to a CSV file from an OU with the following command. (Don’t forget to “import-module ActiveDirectory” when you start PowerShell)

Get-ADUser -Filter * -SearchBase "OU=Administrateurs Systeme,OU=Utilisateurs,dc=domain,dc=com" -properties * | Export-Csv C:\AdminSysteme.csv -Encoding UTF8

This command will grab all users from the Administrateurs Systeme OU and Export it into a CSV file in C:\AdminSysteme.csv in UTF8 encoding for French characters.

2- Open the exported CSV file with Excel. Remove the first line and unused columns from the file. Save As the file and make sure you select the “Save as type” to “CSV (Comma delimited) (*.csv)”. You need to make sure that the file encoding is still UTF8. To do so, while in the “Save As” dialogue, click on “Tool”, “Web Options” and under “Encoding” make sure that the “Save this document as” is set to “Unicode UTF-8)”.  
  
3- Open back the same file and enter all the data you want to modify and save back the file same way as step #2!

4- Open the file in “Notepad” and without changing anything, “Save as” the file again and make sure that the encoding is UTF-8 and if it is not, save as with UTF8.

5- Now that you have all your data in a compatible CSV file. Import the user data with the following command in powershell. 

import-csv "C:\Users\user\Desktop\ADUserList\NEw folder\AdminSysteme1.csv" –Encoding UTF8 |  {Set-ADUser -Identity $_.samaccountname -Description $_.Description -StreetAddress $_.StreetAddress -City $_.City -PostalCode $_.PostalCode -Country $_.Country -Department $_.Departement -Fax $_.Fax -HomePage $_.HomePage -Office $_.Office -OfficePhone $_.OfficePhone -State $_.State -Title $_.Title} 

Known Issues!
All imported properties must be filled with values!
If you have an error of this kind while importing back the csv file;

PS C:\Windows\system32> C:\Users\user\Desktop\ADUserList\New folder\Untitled2.ps1
Set-ADUser : replace
At C:\Users\kelmas\Desktop\ADUserList\New folder\Untitled2.ps1:1 char:104
+ ...  | ForEach {Set-ADUser -Identity $_.samaccountname -Description $_.De ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (calexandre:ADUser) [Set-ADUser], ADInvalidOperationException
    + FullyQualifiedErrorId : ActiveDirectoryServer:0,Microsoft.ActiveDirectory.Management.Commands.SetADUser

Either not all the fields are filled in or the CSV file is not compatible (Comma delimited?, UTF8?)



Comments

Popular posts from this blog

System.Messaging.MessageQueueException (0x80004005): A workgroup installation computer does not support the operation (Public Queue create issue)

Veeam Backup Error : Failed to prepare guest for hot backup. Error: VSSControl

warning: Win32API is deprecated after Ruby 1.9.1; use fiddle directly instead - Chef Development Kit Update