What I would like to do is use a Powershell script to create Contacts within a certain folder in Active Directory from a .csv file. This script should allow me to create the first part of an email address based on the information entered in the .csv file.
We are running our exchange server on Windows Server 2003 still and I have Powershell 3.0 on my computer.
This is a script that is close to what I want but not exactly.
$csv = Import-Csv �C:\Contacts.csv�
foreach($line in $csv)
{
New-MailContact -Name $line.DisplayName -ExternalEmailAddress $line.EmailAddress -OrganizationalUnit �Contacts� -Alias $line.Alias
}
I am not very experienced with Powershell and if anyone can help me out with this I would be very appreciative.
Edit:
As requested, Here is an example of one line in my .csv plus headers
Name,Email
TRUCK 327,9426645555
Best Answer
EDIT: grr...I forgot Exchange 2003...the below only works on Exchange 2007 and above.
For Exchange 2003 you need to use csvde: http://support.microsoft.com/kb/327620
An example of how to format the csv file and the csvde command can be found here: http://forums.msexchange.org/m_1800509533/printable.htm
QUOTE:
Another alternative is a 3rd party utility like AD Bulk Contacts: http://www.dovestones.com/active-directory-contact-import/
OK, here's what I would do (if this were Exchange 2007+ lol)
Setup of csv file
First, open your CSV file in Excel. You need to make your CSV file better for input into PS "script".
Name
toDisplayName
DisplayName Column to a new column called
TempName`Email
toprefix
FirstName
LastName
Email
Getting
FirstName
andLastName
column populated:Highlight all of the data in
TempName
and chooseData
thenText to Columns
and split out based on a space the first and last namesNow copy the first and last names into their respective new columns you created in #4-5.
Getting
Email
column populated:9426645555
in theprefix
column on the same row to the left somewhere, let's say that data is in B3 for example. Here you'll create a formula to concatenate the email prefix with the domain. Something like=CONCATENATE(A2,"@domain.com")
then copy and paste that down the column to get all the email addresses correct.Now at this point you should have rows that have a
DisplayName
,FirstName
,LastName
, andEmail
that has valid info for a single user. Don't worry about the extraneous columns...we won't use them in the input.Save the file now as a CSV file and then verify the CSV file looks accurate for input
On to the Powershell script:
That should at least point you in the direction to get you there. If you get stuck, let me know.