I'm trying to remove orphaned user objects from all mailboxes in our Exchange server.
When I execute this command:
get-mailboxpermission * | where {$_.User -like "S-1-5-21*"} | foreach {$_.Identity.Name}
It correctly returns a list with all the mailboxes that still have orphaned user account permissions set on them.
However, when I try to remove them by doing this:
get-mailboxpermission * | where {$_.User -like "S-1-5-21*"} | remove-mailboxpermission -identity $_.Identity.Name -user $_.User -accessrights $_.AccessRights -deny:$_.Deny
It returns this error:
Cannot bind argument to parameter 'Identity' because it is null.
+ CategoryInfo : InvalidData: (:) [Remove-MailboxPermission], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Remove-MailboxPermission
What am I doing wrong?
Thanks for any help.