Unable to update data from CSV to Active Directory

Error_401 86 Reputation points
2021-07-02T11:11:12.457+00:00

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

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
    2021-07-02T15:23:11.077+00:00

    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