Creating AD Contacts from .CSV

Hello,

I am relatively new to Powershell and below is the script I have to create an AD contact so we can forward all users email to an external address.  In Powershell ISE I get the below error.  Can someone help me out with this please?

Missing closing '}' in statement block.

At line:17 char:13 

 

import-module activedirectory

$contactlist = gc "C:\temp\contacts.csv" 

foreach($line in $contactlist) {

$firstname = $line.split(",")[0]

$lastname = $line.split(",")[1]

$mail = $line.split(",")[2]

$mailnickname = $mail.Split("@")[0]

New-ADObject -Name "$firstname $lastname" -Type "Contact" -Path "fifesd.net/Network Support/Network Exchange Email to GMail contacts/" -DisplayName "$firstname $lastname" `

-OtherAttributes @{ sn=$lastname;

givenName=$firstname;

mail=$mail;

mailNickname=$mailnickname;

targetAddress="SMTP:$mail";

legacyExchangeDN="/o=ExchangeLabs/ou=Exchange Administrative Group/cn=Recipients/cn=$mailnickname";

mAPIRecipient=$false;

            }

 

 

Parents
No Data
Reply
  • HI Tim,

    Thanks for the info.  I couldnt tell if I had problems with my Powershell or if it was the closing statement.  After adding the '}' to the very end here is the error I get.

     

    New-ADObject : The object name has bad syntax

    At line:8 char:14

    +     New-ADObject <<<<  -Name "$firstname $lastname" -Type "Contact" -Path "fifesd.net/Network Support/Network Exchange Email to GMail contacts/" -DisplayName "$firstname $lastname" `

        + CategoryInfo          : NotSpecified: (cn=bruce lee,fi...GMail contacts/:String) [New-ADObject], ADException

        + FullyQualifiedErrorId : The object name has bad syntax,Microsoft.ActiveDirectory.Management.Commands.NewADObject

     

    New-ADObject : The server is unwilling to process the request

    At line:8 char:14

    +     New-ADObject <<<<  -Name "$firstname $lastname" -Type "Contact" -Path "fifesd.net/Network Support/Network Exchange Email to GMail contacts/" -DisplayName "$firstname $lastname" `

        + CategoryInfo          : NotSpecified: (cn=\\ ,fifesd.n...GMail contacts/:String) [New-ADObject], ADException

        + FullyQualifiedErrorId : The server is unwilling to process the request,Microsoft.ActiveDirectory.Management.Commands.NewADObject

Children
No Data