Bulk delete contacts from a distribution group

Hi
In Exchange 2010, from over 1000 external contacts, i have a distribution group with over 300 members.
Basically the customer wants to fill-in correct and full information for those 300 contacts, so i exported them to excel. Now that the customer  finished all his work updating the excel table, i need to delete those 300 contacts, then import them and assign them to the group. How do i do that?

Thanks
Jaime
LVL 2
GreatSolutionsC.I.OAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SreRajCommented:
Hi,

A PowerShell script could a good option here. If you could give me the header row and one example contact data row of the excel file, I could try creating a PowerShell script. Contact data row may not contain actual data, but similar to what you have in your environment.
0
GreatSolutionsC.I.OAuthor Commented:
Hi
Here is a sample .xls with the data and header.

thanks!
Jaime
vaad.xls
0
GreatSolutionsC.I.OAuthor Commented:
...anyone?
0
SreRajCommented:
Please try the following code. It takes input from c:\contacts.xlsx file. It deletes contacts by using their mail address. You will have to modify OrganizationalUnit in the following line.

New-MailContact -Name $CDisplayName -ExternalEmailAddress $CMailAddress -OrganizationalUnit "UserContacts"

Open in new window


Also, please modify Distribution group name in the following line.

Add-DistributionGroupMember "All-Users" -member $CMailAddress

Open in new window


Following is the complete code. This you have to execute from Exchange Management Shell. Please test it with couple of contact objects before running for all contacts. It takes the number of rows in the excel sheet as input, this number includes header row as well.

Import-Module ActiveDirectory
$RowCount = Read-Host "Number of Rows"
$xl = New-Object -COM "Excel.Application"
$xl.Visible = $false
$wb = $xl.Workbooks.Open("C:\contacts.xlsx")
$ws = $wb.Sheets.Item(1)
$Row=1
$Col=1
for ($Row = 2; $Row -le $RowCount; $Row++) {
	$CFirstName = $ws.cells.item($Row, 1).value()
	$CLastName = $ws.cells.item($Row, 2).value()
	$CMailAddress = $ws.cells.item($Row, 3).value()
	$CAddress = $ws.cells.item($Row, 4).value()
	$CCity = $ws.cells.item($Row, 5).value()
	$CZip = $ws.cells.item($Row, 6).value()
	$CCountry = $ws.cells.item($Row, 7).value()
	$CCompany = $ws.cells.item($Row, 8).value()
	$CPhone = $ws.cells.item($Row, 9).value()
	$CFax = $ws.cells.item($Row, 10).value()
	$CMobile = $ws.cells.item($Row, 11).value()
	$CNotes = $ws.cells.item($Row, 12).value()
	$Alias = "$CFirstName"+"$CLastName"
	$CDisplayName = "$CFirstName"+" $CLastName"
	Remove-MailContact -Identity $CMailAddress -Confirm:$False
	New-MailContact -Name $CDisplayName -ExternalEmailAddress $CMailAddress -OrganizationalUnit "UserContacts"
	Set-Contact -Identity $CDisplayName -City $CCity -Company $CCompany -CountryOrRegion $CCountry -Fax $CFax -Firstname $CFirstName -LastName $CLastName -MobilePhone $CMobile -Notes $CNotes -Phone $CPhone -PostalCode $CZip -StreetAddress $CAddress
	Add-DistributionGroupMember "All-Users" -member $CMailAddress
}
$wb.Close()
$xl.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($xl)

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GreatSolutionsC.I.OAuthor Commented:
Excellent excellent excellent. Not only it exactly did the job, now i also learned really powerful stuff with endless possibilities. Thank you very much!!

Jaime
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Exchange

From novice to tech pro — start learning today.