Unable to update data from CSV to Active Directory

Error_401 86 Reputation points


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 -

$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")   
       Write-Warning ("file not updated")   

Here is the csv -

csv as in file -

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"  


Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
5,814 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Ian Xue (Shanghai Wicresoft Co., Ltd.) 29,476 Reputation points Microsoft Vendor

    Hi @Error_401 ,

    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.

    0 comments No comments