Exchange 2007 Shell Script to Batch Mail Contacts
We've create the following shell script that reads in from a .csv file and creates Mail Contacts based on that file. Import-CSV CreateRecipients.csv | foreach {New-MailContact -Name $_.name -ExternalEmailAddress $_.ExternalEmailAddress -org "OU=Students,DC=xavier,DC=local"} This works great but it's only step 1 of a 2 step process for us. Step 2 involves setting up forwarding on existing mailbox-enabled users to point to this newly created custom recipient. To accomplish that, we've come up with the following script... that doesn't work. Import-CSV ForwardRecipients.csv | foreach {set-Mailbox -SamAccountName $_.name -ForwardingAddress $_.ForwardingAddress} Now, we're shocked that we got step 1 to work at all so we're not the least surprised that we've fallen flat on step 2. Assuming that the .CSV file we're importing from in step 2 contains two columns, one with the username and one with the forwarding address (which was already set in step 1 on a mail contact) can anyone offer some advice to fix our script or rewrite it to accomplish our goal? Thanks.
January 15th, 2010 10:50pm

The syntax inside the ForEach loop appears to be wrong. From the command line you could do it like this: (Felicia is my dog, and she does not have an account on Apple Mobile Me.) [PS] C:\>Get-Mailbox -Identity felicia | Set-Mailbox -ForwardingAddress 'felicia@me.com' [PS] [PS] C:\>Get-Mailbox felicia | List SamAccountName, ForwardingAddress SamAccountName : felicia ForwardingAddress : smith.local/MyBusiness/Users/SBSUsers/Felicia Smith (Contact) [PS] C:\> Thus your Import-Csv Loop should look like this: Import-CSV ForwardRecipients.csv | ForEach {Get-Mailbox -SamAccountName $_.name | Set-Mailbox -ForwardingAddress $_.ForwardingAddress} I have only tested and confirmed the command line procedure above, not the Import-CSV, but it should work … (?)MCTS: Messaging | MCSE: S+M | Small Business Specialist
Free Windows Admin Tool Kit Click here and download it now
January 15th, 2010 11:29pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics