Script to remove Exchange inbox of some users by CSV

Jacobo Garrido 60 Reputation points
2023-01-16T10:13:33.7866667+00:00

Hello,

I am working in a Migration Project and I need to remove the inbox of some users and Re-launch the migration again.

Could you send me a script where can i do that? I am so sorry but I am very new in Powershell.

Best Regards

Thx

Microsoft Exchange Online
Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,578 questions
0 comments No comments
{count} votes

Accepted answer
  1. Vasil Michev 108.1K Reputation points MVP
    2023-01-16T10:41:09.01+00:00

    There are several important details here, so it's best to share some additional information on how those mailboxes were created, which migration method you are using, is Directory sync involved and so on.

    To give you some generic instructions, you have few options:

    1. If migrating from on-premises Exchange, use the method outlined in this article
    2. If the mailbox was created/licensed in Exchange Online, remove the Exchange license and wait
    3. As an alternative, destructive option, consider removing the user object in Office 365. Do make sure to backup any and all data you might need from it, if you decide to go this route.

2 additional answers

Sort by: Most helpful
  1. Aholic Liang-MSFT 13,856 Reputation points Microsoft Vendor
    2023-01-17T05:40:59.44+00:00

    Hi @Jacobo Garrido , You can use the New-ComplianceSearch and New-ComplianceSearchAction cmdlets to search for and delete an email message from all mailboxes in your organization. Here is a detailed guide about it:Search for and delete messages in Exchange Server | Microsoft Learn (Please note:A maximum of 10 items per mailbox can be removed at once.)

    2023-1-17-1

    Alternatively, you can refer to the following guide to create a retention policy and apply it to specified mailboxes to delete messages older than one day:

    Create a Retention Policy in Exchange Online | Microsoft Learn


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread


  2. Amit Singh 4,901 Reputation points
    2023-01-18T06:29:33.2066667+00:00

    Please use the below-mentioned command to remove bulk mailboxes in exchange.

    Command to remove the bulk mailboxes by using the above CSV file .

    import-csv c:\remove.csv | Remove-Mailbox -Confirm:$false 

    Also, check this thread for help - https://learn.microsoft.com/en-us/answers/questions/359416/exchange-bulk-import-from-csv-file-to-remove-devic

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.