Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
if you are using Exchange, E-mail Address Policies are the way to go for this – August Feb 6 '13 at 17:50
Do you have available the ActiveDirectory Powershell modules? Is your domain 2008R2, or do you have Active Directory Management Gateway Service installed? – jscott Feb 6 '13 at 18:20
I do not have active directory powershell modules installed yet and yes my domain is 2008 r2. – user157877 Feb 6 '13 at 19:21

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 + ''
    Set-ADUser -Identity $user.samaccountname -EmailAddress $email
share|improve this answer
$users | Foreach-Object { $email = $_.samaccountname ... would be the better choice here. Especially when processing a large amount of data. Read here for more information:… – Tom Mar 16 at 13:09
@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 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 at 13:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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