Updating Users Attributes with a .CSV file and set AD user where every attribute entry is unique.

20 pts.
Tags:
Active Directory
Powershell
I need to take a .csv with each user and their new barcode number and add it to the attribute "barcode".
I have extended the schema to add a new attribute called barcode.
I'm using a .csv file with a test users in it to get the Script right, the file is named adtest.csv I'm using the Administrator:Active Directory module for Windows Powershell I'm using a sample script as a basis from here: "Bulk modifications using Set-AdUser"
            

# Import CSV into variable $userscsv            
    
$users = Import-Csv -Path C:Scriptsadtest.csv            
# Loop through CSV and update users if the exist in CVS file            
            
foreach ($user in $users) {            
#Search in specified OU and Update existing attributes            
 Get-ADUser -Filter "SamAccountName -eq '$($user.samaccountname)'" -Properties * -SearchBase "cn=Students,cn=Users,DC=OURDOMAIN,DC=LOCAL" |            
  Set-ADUser -Replace @{l = "$($user.barcode)"}            
}
I'm getting this error:
Get-ADUser : Directory object not found
At line:3 char:2
+  Get-ADUser -Filter "SamAccountName -eq '$($user.samaccountname)'"
-Properties * ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
    + CategoryInfo          : ObjectNotFound: (:) [Get-ADUser], ADIdentityNotF
   oundException
    + FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.
   Management.ADIdentityNotFoundException,Microsoft.ActiveDirectory.Management.Commands.GetADUser
1

Answer Wiki

Thanks. We'll let you know when a new response is added.

For some reason all the slashes and backslashes are gone from the paste. But they were there…

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: