Solved

Creating Mail Contacts from CSV Exchange 2010 Powershell Command

Posted on 2014-01-30
3
3,974 Views
Last Modified: 2014-01-30
I'm using the below command to create a new mail contact in AD, but it's throwing an error.  It works in a 2008 Active Directory environment, but not on 2003 Active Directory, and it seems to get an error at the Set-Contact -identity portion:

The script is:

Import-CSV C:\adexport.csv | ForEach-Object{
New-MailContact -ExternalEmailAddress $_.mail -Name $_.Name -OrganizationalUnit $_.OUpath
Set-Contact -identity $_.Name -Phone $_.telephoneNumber -MobilePhone $_.Mobile -Office $_.physicalDeliveryOfficeName -Title $_.Title -Department $_.Department
}

The error message i'm getting is:

Error message
0
Comment
Question by:fireguy1125
  • 2
3 Comments
 
LVL 39

Expert Comment

by:footech
Comment Utility
The error appears to be because it thinks Set-Contact is part of the New-Contact command.
Are you sure they are on separate lines and that there is no line continuation character (backtick "`") at the end of the New-Contact command?
You can also try putting a semi-colon at the end of the New-Contact command.
0
 
LVL 1

Author Comment

by:fireguy1125
Comment Utility
It's all within {}  Can you provide the script I should try please?
0
 
LVL 39

Accepted Solution

by:
footech earned 500 total points
Comment Utility
The commands appear correct from what you have above.  I was just explaining what the error is indicating (and I just realized I incorrectly referred to New-MailContact as New-Contact).
I see no reason why the following wouldn't work on any system.
Import-CSV C:\adexport.csv | ForEach-Object{
New-MailContact -ExternalEmailAddress $_.mail -Name $_.Name -OrganizationalUnit $_.OUpath
Set-Contact -identity $_.Name -Phone $_.telephoneNumber -MobilePhone $_.Mobile -Office $_.physicalDeliveryOfficeName -Title $_.Title -Department $_.Department
}

Open in new window

but like I said, you can try adding a semi-colon
Import-CSV C:\adexport.csv | ForEach-Object{
New-MailContact -ExternalEmailAddress $_.mail -Name $_.Name -OrganizationalUnit $_.OUpath;
Set-Contact -identity $_.Name -Phone $_.telephoneNumber -MobilePhone $_.Mobile -Office $_.physicalDeliveryOfficeName -Title $_.Title -Department $_.Department
}

Open in new window

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
This video discusses moving either the default database or any database to a new volume.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now