Search code examples
powershellexchange-server-2010

Clear GrantSendOnBehalfTo on a mailbox exchange - from remote powershell script


To revoke permissions for GrantSendOnBehalfTo from a mailbox, it is pretty well documented, that you would do this:

Set-Mailbox -Identity MyMailbox -GrantSendOnBehalfTo $null

That works when run from powershell and in a local script.

However, if I include it in a script, that runs remote powershell (using New-PSSession etc), it fails with this error:

Couldn't find object "[Microsoft.Exchange.Configuration.Tasks.RecipientIdParameter]". Please make sure that it was spelled correctly or specify a different object. + CategoryInfo : NotSpecified: (:) [], ManagementObjectNotFoundException + FullyQualifiedErrorId : A32A9BAB

So it will not accept $null as a parameter.

How can I get around that?


Solution

  • Realistically, especially if this was Office 365 with DirSync, the easiest way would be to leave the publicDelegates attribute empty in the AD.

    Make sure to use the UPN for the identity (which isn't required if working with a single mailbox):

    Set-Mailbox -identity [email protected] -grantSendOnBehalfTo $null
    

    or

    Set-Mailbox [email protected] -grantSendOnBehalfTo $null