PowerShell Code: ADD an SMTP Address (Proxy Address) To Multiple Users From a .CSV File

In this PowerShell Code, I’ll show an amazing script will add a new SMTP Address \ Proxy Address to a list of users.

This simple code helped me add an addition SMTP address around 500+ users In a matter of a few minutes.

To get this code working, you will need a user SAMACCOUNTNAME and the new SMTP address you would like to add to all the users.

Once, you have the .CSV file ready simply run the script ( I recommend using it on a small number of users first).

Below Is the .CSV file

And below Is the PowerShell Code (make sure you run it from a machine that has Windows Active Directory Module loaded)

Import-module ActiveDirectory
Import-Csv .\SMTPLIST.csv | ForEach-Object
{
$username = $_.samaccountname
$userproxy = $_.emailaddress -split ';'
Set-ADUser -Identity $username -Add @{proxyAddresses= $userproxy}
}

Related:

  • PowerShell Code: Change Multiple Users Attribute In AD With a .CSV File

 

 

2 Replies to “PowerShell Code: ADD an SMTP Address (Proxy Address) To Multiple Users From a .CSV File”

  1. When i run the command i got this error:
    At line:1 char:72
    + Import-Csv .\O3651.csv | ForEach-Object {$username = $_.samaaccountname $userprox …}
    +
    Unexpected token ‘$userproxy’ in expression or statement.

    At line:1 char:72
    + Import-Csv .\O3651.csv | ForEach-Object {$username = $_.samaaccountname $userprox …}
    +
    Unexpected token ‘$userproxy’ in expression or statement.

  2. I get an error also asking for manual entry “Process{0}:

    PS E:\TestArea> Import-Csv E:\TestArea\BrisbaneUsersNew.csv | ForEach-Object
    {
    $username = $_.samaccountname
    $userproxy = $_.emailaddress -split ‘;’
    Set-ADUser -Identity $username -Add @{proxyAddresses= $userproxy}
    }
    cmdlet ForEach-Object at command pipeline position 2
    Supply values for the following parameters:
    Process[0]:

Comments are closed.