I need a script that will change all of my ad users email contact field information. The format will be the "SAMAccountName + @domain.com". I am a powershell noob and need a little help on the syntax. Any help would be appreciated.


Here is what I would do:

Install the Active Directory Powershell Module

Script it like this:

Import-Module ActiveDirectory
$users = Get-ADUser -Filter *
foreach ($user in $users)
    $email = $user.samaccountname + '@domain.com'
    Set-ADUser -Identity $user.samaccountname -EmailAddress $email
  • $users | Foreach-Object { $email = $_.samaccountname ... would be the better choice here. Especially when processing a large amount of data. Read here for more information: blogs.technet.microsoft.com/heyscriptingguy/2014/07/08/… – Tom Mar 16 '16 at 13:09
  • 1
    @Tom Unless you do something like -Properties *, it's not going to be that much of a difference, but fair point – Mathias R. Jessen Mar 16 '16 at 15:10
  • I know - I'm a bit nitpicking. But I think everyone should know the difference between the two methods. – Tom Mar 17 '16 at 13:07

protected by Community May 23 '18 at 9:42

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.