question

Error401-7025 avatar image
0 Votes"
Error401-7025 asked AnshulKumarMINDTREELIMITED-5501 commented

Unable to update data from CSV to Active Directory

Hi,

I have a list of users information in my csv, I want to update suppose the country of a user.
Like here it is United States, I want to update it to France on Active Directory. How may I do so -

Here is the powershell script -

 cls
    
    
 $ADUsers = Import-csv "C:\Updated1.csv"
     
 foreach ($User in $ADUsers)
 {
        
     $Name1 = $User.username
     $Name = $User.email
     $country = $User.country
    
    
     if ($country -eq "United States")
     {
    
     $test = Get-ADUser -filter {Name -eq $Name1}| Set-ADUser -Country -eq "France"
    
        Write-Host ("Updated") 
     }
    
     else
     {
        Write-Warning ("file not updated") 
       }

Here is the csv -
111330-image.png

csv as in file -

 firstname,middleInitial,lastname,username,email,streetaddress,city,zipcode,state,country,department,password,telephone,jobtitle,company,ou
 Dragon ,,Fruit,DragonAD,DragonAD@activedirectorypro.com,2749 Liberty Street,Dallas,75202,TX,United States,Marketing,ptwadgjmptw1.,214-800-4820,Marking Specialist,AD Pro,"OU=Developer,OU=Department,DC=test,DC=com"


Thanks



windows-active-directory
image.png (14.4 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,

Is there any update? Have you got a chance to verify the below suggestion?
Please feel free to let us know if more assistance is needed. If the reply is helpful, please “Accept Answer” to help other community members find it more easily,

0 Votes 0 ·

Hi, if the posted answer resolves your question, please mark it as the answer by clicking the check mark. Doing so helps others find answers to their questions.

0 Votes 0 ·

1 Answer

IanXue-MSFT avatar image
0 Votes"
IanXue-MSFT answered

Hi @Error401-7025 ,

The "-eq" operator should be removed from Line 17 and you have to use the country code "Fr" instead of "France" for the country property.

 Get-ADUser -filter {Name -eq $Name1}| Set-ADUser -Country -eq "France"  

Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.