remove specific contact list under outlook

Hi Experts,

I have a list of users that need to be removed from users contact list.   I want to do that using script through GP.

I think best approach is to go through existing user's CSV file and remove it if username available under txt file.

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.

Hi uknet

Try this script

$olSession = (New-Object -ComObject Outlook.Application).Session
$olSession.Logon('Outlook') #Outlook is the profile name
$contactsFolder = 10
$tempFolderName = 'temp_folder_' + (get-date -Format ddmmyyyhhmmss)
$myContacts = $olSession.GetDefaultFolder($contactsFolder).Items
$tempFolder = $olSession.GetDefaultFolder($contactsFolder).Folders.Add($tempFolderName)

Write-Host "..getting unique items"
$uniqueContacts = $myContacts | Sort FullName -Unique

#move contacts to temp contacts folder
foreach ($Contact in $uniqueContacts) {
$Contact.Move($tempFolder) | foreach-object {Write-Progress "Backup unique items to temp folder..." $_.FullName; $_.FullName} | Out-Null

#read default contacts again and dump to csv
Write-Host "..export duplicates to csv"
$duplicates = $olSession.GetDefaultFolder($contactsFolder).Items
$duplicates | Export-Csv duplicates.csv

#delete all contacts left in default contacts folder
Foreach ($duplicate in $duplicates){
$duplicate.Delete() | foreach-object {Write-Progress "Deleting duplicate..." $_.FullName; $_.FullName} | Out-Null

Hope this help

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
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
VB Script

From novice to tech pro — start learning today.