Solved

Creating Mail Contacts from CSV Exchange 2010 Powershell Command

Posted on 2014-01-30
3
4,086 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 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 500 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

0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Outbound messages randomly are blank. 7 32
AD and SQL Server 2016 2 31
Antivirus in server 3 21
Powershell and robocopy 2 13
This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video discusses moving either the default database or any database to a new volume.

821 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