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
  • Hey sjkeith,

    You need to close of your FOR..EACH loop by adding another '}' at the end of your code, that's what's causing the error.

    NB PowerShell has a cmdlet to allow you to directly import .csv files, Import-CSV.  You can get more information on it by the standard Get-Help command.

Children
No Data