Welcome to Powergui.org - an open source community for Windows Powershell

PowerGUI.org PowerGUI.org and blogs

Forums » Request a Script

Thread: add emails from csv

This question is not answered. Helpful answers available: 2. Answered answers available: 1.


Permlink Replies: 1 - Pages: 1 - Last Post: Dec 3, 2009 1:44 PM by: Shay Levy
jk2ny

Posts: 1
Registered: 12/3/09
add emails from csv
Posted: Dec 3, 2009 11:34 AM
 
  Click to reply to this thread Reply

Hi I am trying to add email aliases in exchange 2007 from a csv file

The csv file I have looks like this:
displayName,mail,proxyAddress,ProxyAddress2,proxyAddress3

What I would like to do is:

For each displayname
add mail as primary address
if listed add proxyaddress
if listed add proxyaddress2
if listed add proxyaddress3


Thanks




Shay Levy


Posts: 1,919
Registered: 1/31/08
Re: add emails from csv
Posted: Dec 3, 2009 1:44 PM   in response to: jk2ny
 
  Click to reply to this thread Reply

I didn't test but this should work:

import-csv users.csv | foreach {

    $mailbox = get-mailbox $_displayName

    $emails = $_ | foreach {$_.proxyaddress,$_.proxyaddress2,$_.proxyaddress3} | where {$_}
    if($emails)
    {
     $mailbox.emailAddresses+=$emails
     set-mailbox $mailbox -emailAddresses $emails
    }
   
    set-mailbox $mailbox -primaryEmailAddress $_.email
}




Shay Levy [MVP]
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar
Legend
MVP: 2501 + pts
Guru: 2001 - 2500 pts
Expert: 751 - 2000 pts
Enthusiast: 31 - 750 pts
Novice: 0 - 30 pts
Moderators
Helpful answer (5 pts)
Answered (10 pts)

Point your RSS reader here for a feed of the latest messages in all forums