Guest User

Untitled

a guest
Mar 26th, 2016
1,532
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $users = Get-ADUser -SearchBase "ou=Company Users,dc=domain,dc=org" -Filter *
  2. foreach ($user in $users) {
  3. $pax = (Get-ADUser -Identity $user -Properties proxyaddresses).proxyaddresses
  4. $firstname = (Get-ADUser -Identity $user -Properties givenname).givenname
  5. $lastname = (Get-ADUser -Identity $user -Properties surname).surname
  6. foreach ($address in $pax) {
  7.     if ($address -cmatch '^x500:.') {
  8.         $x500 = $address
  9.     }
  10.     }
  11. $newList = @()
  12. $newList += "SMTP:$firstname.$lastname@company.org"
  13. $newList += "smtp:$firstname.$lastname@company.onmicrosoft.com"
  14. Set-ADUser -Identity $user -Clear proxyaddresses
  15. foreach ($address in $newList) {
  16. Set-ADUser -Identity $user -Add @{
  17.         'proxyAddresses' = $address
  18. }
  19.     }
  20.     Set-ADUser -Identity $user -Add @{
  21.         'proxyAddresses' = $x500
  22. }
  23. }
RAW Paste Data