2

Good morning!

I have a quick question. How would I delete the mail contact associated with a certain user? This is what I have tried:

Get-Mailbox 'jsmith' | select ForwardingAddress | Remove-MailContact

This throws a command piping error:

The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do
 not match any of the parameters that take pipeline input.
    + CategoryInfo          : InvalidArgument: (@{ForwardingAdd...ding/J Smith}:PSObject) [Remove-MailContact], ParameterBindingException
    + FullyQualifiedErrorId : InputObjectNotBound,Remove-MailContact

I then tried this, just in case:

Get-Mailbox 'jsmith' | select ForwardingAddress | Remove-MailContact $_

And received this:

Cannot bind argument to parameter 'Identity' because it is null.
    + CategoryInfo          : InvalidData: (:) [Remove-MailContact], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Remove-MailContact

However, if I run just this:

Get-Mailbox 'jsmith' | select ForwardingAddress 

I'm given this response:

ForwardingAddress
-----------------
ObfuscatedDomain.com/E-mail Forwarding/J Smith

The names have been changed to protect the innocent.

Clearly, I'm not that great with Exchange powershell, but I'm learning haha. I'm assuming the issue is because the data returned from select ForwardingAddress is not an identifier Remove-MailContact will accept. However, there are only two 'Forwarding' properties of Get-Mailbox.

2 Answers 2

1

First, the ForwardingAddress property does not have to correspond to a Mail Contact. (I have several that list other mailboxes and quite a few that list distribution groups). Just remember that as we continue.

The problem is your use of the SELECT verb and how it is returning a portion of the property instead of the full object. Try: Remove-MailContact $(Get-Mailbox "jsmith").ForwardingAddress

This is getting the object that is the forwarding address. Another alternative (if you don't mind multi-lining it) would be:

$mailbox = Get-Mailbox "jsmith"
$forward = $mailbox.ForwardingAddress
Remove-MailContact $forward

Remember that all of this assumes the ForwardingAddress is referencing an object of type MailContact, which isn't guaranteed (it can be any type of Direcotry.ADObjectId)

2

I believe you are looking for Disable-MailUser <username>, which will disable the email account portion of the account, but leave the AD user account intact.

If you are looking to remove the email attributes of a contact that does not have a User account in Active Directory, then you are looking for Disable-MailContact <username>.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .