locked
PS Script to add proxyaddress to all users in a specified OU (edited) RRS feed

  • Question

  • Hi,

    We receently purchased an additional domain which we would like added to all user's accounts as a secondary address. Instead of going to each user account - Attribute editor - ProxyAddresses and additing it here (in AD) i was hoping someone could help me with a powershell script that would add the new address to all user's accounts in a specific OU.

    For example, say our primary domain was @test.co.uk and we have now purchased @test.com, we would like this added as a secondary email to all user's accounts. 

    example:

    Harry.potter@test.co.uk (primary)

    Harry.potter@test.com (secondary - which we'd like to add via PS) 

    Thanks in advance. 


    • Edited by Imran Perez Tuesday, November 13, 2018 11:06 AM
    Tuesday, November 13, 2018 10:38 AM

Answers

  • Hey guys, 

    Just thought i'd update this thread with what i was looking for, this below is not actually a cmd line i created but borrowed from someone else with some modification.

    so it effectivly sets the secondary address by using givenname.surname@test.com 

    Get-ADUser -Filter 'Name -like "*"' -SearchBase 'OU=TEST OU,OU=' -Properties * | % {Set-ADUser $_ -add @{proxyAddresses="smtp:"+ $_.GivenName + '.' + $_.Surname +"@test.com"}}


    • Marked as answer by Imran Perez Monday, November 19, 2018 3:45 PM
    • Edited by Imran Perez Monday, November 19, 2018 3:45 PM
    Monday, November 19, 2018 3:45 PM

All replies

  • Your post is completely unreadable.  You must disable Grammerly on this site.  Please fix your post.


    \_(ツ)_/

    Tuesday, November 13, 2018 10:41 AM
  • Last chance.  Please fix your post.  It is unreadable.


    \_(ツ)_/

    Tuesday, November 13, 2018 10:51 AM
  • Hi, sorry had to complete re-write whole thing. 
    Tuesday, November 13, 2018 11:04 AM
  • You are asking about email addresses.  They can be easily updated with Set-AdUser cmdlet.

    Look in the Gallery for scripts that do this or post your script with any errors.


    \_(ツ)_/

    Tuesday, November 13, 2018 11:06 AM
  • You are asking about email addresses.  They can be easily updated with Set-AdUser cmdlet.

    Look in the Gallery for scripts that do this or post your script with any errors.


    \_(ツ)_/

    I have this one but it is only for doing one user at a time, how can i change this to affect the whole OU? 

    Set-ADUser harry.potter -Add @{ProxyAddresses="smtp:harry.potter@test.com"}

    Tuesday, November 13, 2018 11:14 AM
  • Just use a wildcard to select all users with Get-AdUser then pipe that into a loop and set each user as needed.

    As noted - look in the Gallery for scripts that do exactly what you ask.


    \_(ツ)_/

    Tuesday, November 13, 2018 1:46 PM
  • Hi,

    Thanks for your question.

    I agree with Jrv.

    For example:

    Get-ADUser -Filter * | ForEach-Object {Set-ADUser $_.SamAccountName -Add @{ProxyAddresses="smtp:harry.potter@test.com"}}
    You can also find scripts in the Gallery that do what you are asking:


    Best Regards,

    Lee


    Just do it.

    Wednesday, November 14, 2018 9:53 AM
  • add second addressspace in your exchange environment. Exchange will add it for you. Then you need no script and code.

    Chris

    Wednesday, November 14, 2018 6:23 PM
  • Hi,

    Thanks for your question.

    I agree with Jrv.

    For example:

    Get-ADUser -Filter * | ForEach-Object {Set-ADUser $_.SamAccountName -Add @{ProxyAddresses="smtp:harry.potter@test.com"}}
    You can also find scripts in the Gallery that do what you are asking:


    Best Regards,

    Lee


    Just do it.

    Hey,

    Thank you for your response, i have to apolgise my knowledge of powershell is very limited. 

    The command line you posted, what does i filter by?

    I'll take a look at the gallary, thanks.

    Thursday, November 15, 2018 11:25 AM
  • add second addressspace in your exchange environment. Exchange will add it for you. Then you need no script and code.

    Chris

    Thanks or your response, if our setup included exchange it would make it so much easier however we Have AD only and the user accounts then get synced to our GSuite platform. 

    This is why i was looking for a cmd or something to add secondary addresses in bulk (even from csv) to users in AD. Cant seem to find what im looking for in the gallery.

    Monday, November 19, 2018 8:11 AM
  • Hi,

    Thanks for your question.

    I agree with Jrv.

    For example:

    Get-ADUser -Filter * | ForEach-Object {Set-ADUser $_.SamAccountName -Add @{ProxyAddresses="smtp:harry.potter@test.com"}}
    You can also find scripts in the Gallery that do what you are asking:


    Best Regards,

    Lee


    Just do it.


    Your example has a major bug (why would you want to set the same email address across whole domain???) and it is recommended to NOT run without some modifying.  
    • Edited by Mekac Monday, November 19, 2018 10:42 AM
    Monday, November 19, 2018 10:40 AM
  • Hey guys, 

    Just thought i'd update this thread with what i was looking for, this below is not actually a cmd line i created but borrowed from someone else with some modification.

    so it effectivly sets the secondary address by using givenname.surname@test.com 

    Get-ADUser -Filter 'Name -like "*"' -SearchBase 'OU=TEST OU,OU=' -Properties * | % {Set-ADUser $_ -add @{proxyAddresses="smtp:"+ $_.GivenName + '.' + $_.Surname +"@test.com"}}


    • Marked as answer by Imran Perez Monday, November 19, 2018 3:45 PM
    • Edited by Imran Perez Monday, November 19, 2018 3:45 PM
    Monday, November 19, 2018 3:45 PM