Monday, 5 September 2016

PowerShell Script: Update AD attributes using CSV

Hi All, in this post I am going to share information on how can you update an attribute(s) in AD for multiple objects. In this post, I am using a CSV file that contains users’ First Name, Last Name, their login name and Employee ID. I wanted to update Employee ID for all the users listed in CSV file.

To achieve this, I have complied a PowerShell script that uses CSV file and update AD attributes for multiple users.

CSV file: I saved CSV file in C:\ADTest.CSV.




I ran following PowerShell script as admin. This script import CSV data, updates EmployeeID data for each login name (sAMAccountName) listed in CSV file.

#Import Active Directory module

Import-Module ActiveDirectory

#Import CSV file

$Obj=Import-Csv "C:\ADTest.csv"

foreach($Usr in $Obj)
{
Get-ADUser -Filter "sAMAccountName -eq '$($u.sAMAccountName)'" -properties * | set-aduser -replace @{employeeID="$($u.employeeID)"} -PassThru
}

I hope you find this useful.

Disclaimer: www.TechieTalks.co.uk does not conceal the possibility of error and shortcomings due to human or technical factors. www.TechieTalks.co.uk does not bear responsibility upon any loss or damage arising from conduct or activities related to the use of data and information contained in this blog.

No comments:

Post a Comment