?
Solved

Creating Mail Contacts from CSV Exchange 2010 Powershell Command

Posted on 2014-01-30
3
Medium Priority
?
4,228 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 40

Expert Comment

by:footech
ID: 39820998
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
ID: 39821022
It's all within {}  Can you provide the script I should try please?
0
 
LVL 40

Accepted Solution

by:
footech earned 2000 total points
ID: 39821215
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

1

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will help to fix the below error for MS Exchange server 2010 I. Out Of office not working II. Certificate error "name on the security certificate is invalid or does not match the name of the site" III. Make Internal URLs and External…
Here's a look at newsworthy articles and community happenings during the last month.
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 shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Suggested Courses
Course of the Month14 days, 5 hours left to enroll

801 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