Delete Mail contacts in bulk using Powershell

Anonymous
2023-08-17T11:55:00+00:00

Hi, I have been trying to delete mail contacts from my organization through Powershell using this cmdlet:

on our Exchange Server 2016 via ' Exchange Management Shell '

Import-Csv C:\contacts.csv | ForEach-Object {Remove-MailContact -Name $_.Name -FirstName $_.FirstName -LastName $_.LastName -DisplayName $_.DisplayName -ExternalEmailAddress $_.ExternalEmailAddress -OrganizationalUnit  <OU>}

However, when run the script I receive error:

A parameter cannot be found that matches parameter name 'Name'.

+ CategoryInfo          : InvalidArgument: (:) [Remove-MailContact], ParameterBindingException 

+ FullyQualifiedErrorId : NamedParameterNotFound,Remove-MailContact 

+ PSComputerName        : lbe-sh-exch-001.lbe.local 

Please assist?

Windows for business Windows Server User experience PowerShell

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question. To protect privacy, user profiles for migrated questions are anonymized.

0 comments No comments
{count} votes
Accepted answer
  1. Anonymous
    2023-08-18T02:03:37+00:00

    Hi,

    The error message indicates that the "Name" parameter is not vaild for the Remove-MailContact cmdlet. You can use the "Identity" parameter which accepts any value that uniquely identifies the mail contact. For example:

    • Name
    • Alias
    • Distinguished name (DN)
    • Canonical DN
    • Email address
    • GUID

    Import-Csv C:\contacts.csv | ForEach-Object {Remove-MailContact -Identity $_.Name}

    Please refer to below help file for more details.

    Remove-MailContact (ExchangePowerShell) | Microsoft Learn

    Best Regards,

    Ian Xue

    3 people found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2023-08-18T11:51:16+00:00

    This has resolve the issue. Many thanks for you help and swift response! :)

    0 comments No comments
  2. Anonymous
    2023-09-12T01:41:35+00:00

    If the reply is helpful, please help to mark it as answer so that it could be found more easily.

    Best Regards,

    Ian Xue

    0 comments No comments