Update 'State' field in AD based on 'Location' field using a script

Hi there,

I’m hoping for some pointers - we’ve got a DDG that monitors the State field to pull users in, and I want to create a script that monitors the Location field for certain text - so if in Location a user has the text ‘Balmy Street’ the State field gets updated to show ‘London’. Still working out how to create the conditional arguments so any directions would be greatly appreciated.

Well, that’s a big set of conditions. It might be easier to create a lookup hash table.

$lookup = @{'Las Vegas'='Nevada';'Phoenix'='Arizona'}
$lookup['Las Vegas'] # returns 'Nevada'

It’s then a little easier to retrieve the value (state) from the key (city).

There’s no way to “bulk” this; you’re going to need to go through each record one at a time, check them, and update them appropriately. But with a lookup table you could make it a bit easier.

BTW, by “bulk,” I mean there’s no way to send a set of queries to the domain controller that will just make it do all of this - you’re going to be enumerating more or less every user in the domain, unless you’ve got some way of narrowing down the objects that need to be changed (e.g., ones with a blank State).