Today we will take a look at Export-Mailbox cmdlet and how we can make use of it at the simplest level.
Of course there are few important requirements with respect to group membership for the account we will be using.
Lets setup things systematically, don’t you think creating a dedicated group will be a good idea? which ever user needs to perform Export Mailbox task can be added to a group and that’s it.
We will create a group named “Mailbox Import Export Group”, its going to be a Universal Security group.
Lets have a user account too, named as “MBIE”, add this user to “Mailbox Import Export Group”
Also to run Export-Mailbox cmdlet the user should be a member of “Organization Management”, “Server Management” in Exchange Organization and “Local Administrators” on target servers.
For this we will add our created group to “Organization Management” and “Server Management” group through ADUC/Domain.com/Microsoft Exchange Security Groups.
As Organization Management is a member of “Local Administrators” group on all Exchange Servers we don’t need to add any custom security GPO.
Next, we will give our group “mailbox import export group” Mailbox Import Export management role permission so that we can run Export-Mailbox cmdlet.
For this we will be using New-ManagementRoleAssignment cmdlet.
New-ManagementRoleAssignment –Role “Mailbox Import Export” –SecurityGroup “msexchange\Mailbox Import Export Group”
Next, lets give user MBIE FullAccess permission on all mailbox in exchange organization, we can even give FullAccess permission on specific mailboxes and all mailboxes on a specific mailbox server, but for simplicity we will use all mailboxes as I have one Mailbox server in my lab.
Get-Mailbox –Server Exchange1 –ResultSize Unlimited | Add-MailboxPermission –User MBIE –AccessRights FullAccess –InheritanceType All
Let us not dive into exporting mailbox.
We will be removing a specific message from all exchange mailboxes which has “Tender” keyword in subject.
I have 2 users configured, Wasim.Shaikh and Urooj.Shaikh.
An email is sent from Wasim to Urooj with a subject Tender.
On Exchange server as I am logged in as Administrator, lets Run Exchange management shell with MBIE credentials. Why?
Coz we assigned Mailbox Import Export Role, so only this account will be able to run the cmdlet and not the administrator.
Ok, so once the powershell window is open we will run
Get-Mailbox –Server Exchange1 –ResultSize Unlimited | Export-Mailbox –SubjectKeywords Tender –IncludeFolders “\Inbox” -DeleteContect
In result you will get loads of matter, but thing to make note is “StandardMessagesDeleted” which shows value of 1.
We can know that 1 message was deleted from this users inbox, the users name will be displayed above if you scroll.
If you check the outlook, The message that had Tender in subject has been deleted.
I will continue this article with much more details.