none
Powershell Script for updating incorrect address for all users in a specific location

    Question

  • Hi all,

    Several offices in my organisation recently moved and as such we have some users with an incorrect address.  Is it possible to loop through these users in PowerShell and update their address fields?  I'm thinking, looking at the properties on this thread that I can filter on the Office Property and then update other properties like the street address, post code and other fields.

    Any pointers or example scripts are appreciated as I've not attempted this before.

    Many thanks
    Steven


    Steven Andrews
    SharePoint Business Analyst: Acas
    Blog: baron72.wordpress.com
    Twitter: Follow @backpackerd00d
    My Wiki Articles: CodePlex Corner Series
    Please remember to mark your question as "answered" if this solves (or helps) your problem.


    • Edited by Steven Andrews Tuesday, April 18, 2017 12:03 PM Updated grammar
    Tuesday, April 18, 2017 12:01 PM

Answers

  • Hi Steven,

    Please try the following script. I have tested and it worked for me. Just replace values.

    $users = Get-ADUser -SearchBase "OU=<USers OU Name>,dc=yourdomain,dc=com" -Filter * 
    
    foreach ($user in $users) {
    
    Set-ADUser $user.samaccountname -city "new city" -POBox "New POBox" -PostalCode "new postal code" -State "new state" -StreetAddress "new street address" -Country "Region code of country suppose IN for India"
    
    }

    https://serverfault.com/questions/476135/how-to-change-all-users-ad-email-contact-using-powershell

    Let me know if you need more help.

    Karim



    • Edited by Karim Buzdar Tuesday, April 18, 2017 5:09 PM Formatted
    • Marked as answer by Steven Andrews Thursday, April 20, 2017 4:10 PM
    Tuesday, April 18, 2017 5:07 PM

All replies

  • Hi Steven,

    Where new addresses of AD users placed? in any file? Are users part of single domain?  Please can you give more detail?

    Karim

    Tuesday, April 18, 2017 12:54 PM
  • Hi Karim,

    Thanks for your response.  All usres are on the same AD domain,  And the address is a new postal address.

    Does that help?

    Thanks
    Steven


    Steven Andrews
    SharePoint Business Analyst: LiveNation Entertainment
    Blog: baron72.wordpress.com
    Twitter: Follow @backpackerd00d
    My Wiki Articles: CodePlex Corner Series
    Please remember to mark your question as "answered" if this solves (or helps) your problem.

    Tuesday, April 18, 2017 1:51 PM
  • Hi Steven,

    Please try the following script. I have tested and it worked for me. Just replace values.

    $users = Get-ADUser -SearchBase "OU=<USers OU Name>,dc=yourdomain,dc=com" -Filter * 
    
    foreach ($user in $users) {
    
    Set-ADUser $user.samaccountname -city "new city" -POBox "New POBox" -PostalCode "new postal code" -State "new state" -StreetAddress "new street address" -Country "Region code of country suppose IN for India"
    
    }

    https://serverfault.com/questions/476135/how-to-change-all-users-ad-email-contact-using-powershell

    Let me know if you need more help.

    Karim



    • Edited by Karim Buzdar Tuesday, April 18, 2017 5:09 PM Formatted
    • Marked as answer by Steven Andrews Thursday, April 20, 2017 4:10 PM
    Tuesday, April 18, 2017 5:07 PM
  • Hi Karim,

    Thanks for this.  Looks like a step in the right direction.  The -Filter * clause selects everyone / everything in the address book though doesn't it?  Can I amend this to only select a specific group of users?  Say in the Birmingham office


    Steven Andrews
    SharePoint Business Analyst: LiveNation Entertainment
    Blog: baron72.wordpress.com
    Twitter: Follow @backpackerd00d
    My Wiki Articles: CodePlex Corner Series
    Please remember to mark your question as "answered" if this solves (or helps) your problem.

    Wednesday, April 19, 2017 1:12 PM
  • Hi Steven,

    Yes, you can select specific users using -Filter parameter.


    / Karim
    Wednesday, April 19, 2017 1:15 PM