[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4326
  • Last Modified:

Creating Mail Contacts from CSV Exchange 2010 Powershell Command

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
fireguy1125
Asked:
fireguy1125
  • 2
1 Solution
 
footechCommented:
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
 
fireguy1125Author Commented:
It's all within {}  Can you provide the script I should try please?
0
 
footechCommented:
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

 The Evil-ution of Network Security Threats

What are the hacks that forever changed the security industry? To answer that question, we created an exciting new eBook that takes you on a trip through hacking history. It explores the top hacks from the 80s to 2010s, why they mattered, and how the security industry responded.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now