troubleshooting Question

Powershell: How to compare AD user accounts to CSV record row

Avatar of bndit
bndit asked on
8 Comments1 Solution3431 ViewsLast Modified:
I have a script that provisions AD user accounts based on a daily user export from HR. This export has your typical information about the employee (location, title, employeenumber, etc.)

Currently, I update every single record in AD even if there was no change to the employee record. However, I'm trying to be more efficient and ONLY process new employees and employees that have had changes to their information (title, location, last name change, etc)

I think I can use hashtables to identify the new employees something like this:

$ADUsers = Get-QADuser -SearchRoot "mydomain" -Sizelimit 0 | Group-Object -Property UNIQUEID -AsHashTable
$Employees = Import-Csv -Path C:\temp\employees.csv | Group-Object -Property UNIQUE_ID -AsHashTable
$NewEmployees = New-Object System.Collections.ArrayList
$Employees.GetEnumerator() | % {
		$NewEmployees.Add($_.Key) | Out-Null

However, aside from checking every single row against the data that you're monitoring in the AD user account (i.e. you want to update the AD user account when either of 3 fields has changed 1) Title 2) last name, or 3) location), I'm not sure how I can accomplish this?  Do you have any ideas? suggestions? Something I was thinking about was computing a hash value (not even sure if this is available in poweshell) for the row in the CSV and compute another hash for the AD user data (you'd have to select the right properties etc), and then do a compare (Compare-Object?)? Would the use of a database table help in this case? Load the existing AD user data into one table and compare it to the data in second table, which contains AD user data from the last run and only get the records that are different (Select query?)?

Anyway, thanks for your help.
Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros