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

Welcome Forums General PowerShell Q&A Update 'State' field in AD based on 'Location' field using a script

This topic contains 1 reply, has 2 voices, and was last updated by

4 years, 5 months ago.

  • Author
  • #22224

    Topics: 1
    Replies: 0
    Points: 0
    Rank: Member

    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.

  • #22228

    Topics: 13
    Replies: 4872
    Points: 1,813
    Helping HandTeam Member
    Rank: Community Hero

    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).

The topic ‘Update 'State' field in AD based on 'Location' field using a script’ is closed to new replies.