question

JohnAdams-0930 avatar image
0 Votes"
JohnAdams-0930 asked RichMatheisen-8856 edited

Powershell script to compare AD to Csv Export - Update missing attribute with Csv data

Hello,

We have a process where an export for users is dumped to a location as a csv file. The csv file has two columns: Extensionattribute10 and Extensionattribute11.

We need to check Ad for users where Extensionattribute10 is empty and then update that user from the data in the csv file. All users have Extensionattribute11 so we can

use that column to callback to the csv and get the proper Extensionattribute10 data that should be set on the user.

Any tips of assistance is much appreciated.

Thank you

windows-server-powershellwindows-active-directory
· 7
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Are you sure that ALL users in the AD have a populated ExtensionAttribute11? What about users that aren't mail-enabled in some way? What about built-in accounts? Service accounts? Disabled accounts? What about accounts that should have a populated ExtensionAttribut11 but, for whatever reason, do not?

How many users are represented in that CSV? 100, 1000, 10,000, more?

If there are a sizable number of rows in the CSV it might make sense to build a hash from the CSV using ExtensionAttribute11 as the key and ExtensionAttribute10 as the data.

If you're sure that every user that should have a populated ExtensionAttribute truly does have one then use "Get-ADUser -filter "extensionattribute11 -like '' -and extensionattribute10 -notlike ''" to get only the users with missing extensionattribute10 values. If their extensionattribute11 is a key in the hash then populate extensionattribute 10 using the value in the hash.



0 Votes 0 ·
JohnAdams-0930 avatar image JohnAdams-0930 RichMatheisen-8856 ·

All active users in AD have extensionattribute11 populated. All other accounts built-in, service accounts, disabled accounts, etc don't have the value.

There are about 20k users in the csv but not all them need to be updated.

The issue is that all active users in AD don't have extensionattribute10 populated (most do but not all) and that information is in the csv export. We need to search for all users that don't have extensionattribute10 and then call the csv file with the proper data to update the users account.

Thank you

0 Votes 0 ·

See the 3rd and 4th paragraph in my earlier reply.

If you simply look for users that don't have a populated extensionattribute10 you're going to find all the users that need attention AND the inactive accounts, service accounts, etc.

The problem with using a CSV (or an array) to store the two attribute values is that there's no way to quickly find what you're looking for. You'd either have to search the entire CSV for each user missing extensionattribute10, or store the CSV as an array of arrays and then search that sequentially.

0 Votes 0 ·
Show more comments

0 Answers