Permanently delete users mailbox and archive mail boxes

%3CLINGO-SUB%20id%3D%22lingo-sub-1543461%22%20slang%3D%22en-US%22%3EPermanently%20delete%20users%20mailbox%20and%20archive%20mail%20boxes%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1543461%22%20slang%3D%22en-US%22%3E%3CP%3EI%20need%20a%20PS%20script%20that%20will%20permanently%20delete%20a%20list%20of%20Users%20Mailboxes%20and%20the%20associated%20Archive%20mailbox%20for%20the%20same%20users.%3C%2FP%3E%3CP%3EAll%20these%20users%20are%20in%20Specific%20AD%20OU's%20if%20that%20helps%20but%20i%20obviously%20have%20a%20csv%20list.%3C%2FP%3E%3CP%3ECan%20someone%20advise%20the%20best%20process%20and%20if%20there%20are%20any%20Powershell%20scripts%20out%20there.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMany%20thanks%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1543461%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3E2013%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExchange%20Server%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1543486%22%20slang%3D%22en-US%22%3ERe%3A%20Permanently%20delete%20users%20mailbox%20and%20archive%20mail%20boxes%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1543486%22%20slang%3D%22en-US%22%3EYou%20need%20to%20remove%20users%20licenses%20from%20O365%2C%20for%20that%20first%20you%20need%20to%20know%20which%20user%20has%20which%20license.%20If%20you%20have%20only%20one%20type%20of%20license%20it%20shouldn't%20be%20difficult%20to%20remove%20them.%3CBR%20%2F%3EFirst%20get%20the%20license%20using%20below%3A-%3CBR%20%2F%3EGet-MsolAccountSku%20%7C%20Select%20AccountSkuID%3CBR%20%2F%3Eyou%20will%20get%20something%20like%20yourtenant%3AEnterprisePack%3CBR%20%2F%3ENow%20you%20can%20use%20the%20CSV%20you%20have%20to%20remove%20the%20licenses%20using%3A-%3CBR%20%2F%3EImport-Csv%20C%3A%5CContacts.csv%20%7CForEach%7BSet-MsolUserLicense%20-UserPrincipalName%20%24_.UPN%20-RemoveLicenses%20%22yourtenant%3AENTERPRISEPACK%20%22%20%7D%3CBR%20%2F%3EPlease%20Note%20that%20CSV%20should%20have%20UPNs.%3CBR%20%2F%3E%3CBR%20%2F%3EOr%20you%20can%20just%20delete%20the%20user%20from%20O365%20and%20let%20AAD%20Connect%20sync%20the%20user%20again.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1547938%22%20slang%3D%22en-US%22%3ERe%3A%20Permanently%20delete%20users%20mailbox%20and%20archive%20mail%20boxes%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1547938%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F333418%22%20target%3D%22_blank%22%3E%40DeepakRandhawa%3C%2FA%3E%26nbsp%3B%20Sorry%20I%20am%20talking%20about%20on%20prem%20exchange%202013.%20%3A)%3C%2Fimg%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1548070%22%20slang%3D%22en-US%22%3ERe%3A%20Permanently%20delete%20users%20mailbox%20and%20archive%20mail%20boxes%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1548070%22%20slang%3D%22en-US%22%3EOkay%2C%20this%20should%20remove%20mailboxes%3CBR%20%2F%3EImport-Csv%20C%3A%5CContacts.csv%20%7C%20ForEach%20%7B%20Disable-Mailbox%20%24_.EmailAddress%20%7D%3CBR%20%2F%3Eif%20you%20are%20prompted%20to%20confirm%20for%20every%20mailbox%20just%20add%20-confirm%3A%24false%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1553429%22%20slang%3D%22en-US%22%3ERe%3A%20Permanently%20delete%20users%20mailbox%20and%20archive%20mail%20boxes%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1553429%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F333418%22%20target%3D%22_blank%22%3E%40DeepakRandhawa%3C%2FA%3E%26nbsp%3B%20thanks%20for%20this%20does%20this%20also%20remove%20the%20Archive%20files%20that%20are%20in%20a%20separate%20db%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1553538%22%20slang%3D%22en-US%22%3ERe%3A%20Permanently%20delete%20users%20mailbox%20and%20archive%20mail%20boxes%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1553538%22%20slang%3D%22en-US%22%3Edisabling%20primary%20mailbox%20also%20disables%20archive%20mailbox%3C%2FLINGO-BODY%3E
Highlighted
Contributor

I need a PS script that will permanently delete a list of Users Mailboxes and the associated Archive mailbox for the same users.

All these users are in Specific AD OU's if that helps but i obviously have a csv list.

Can someone advise the best process and if there are any Powershell scripts out there.

 

Many thanks

5 Replies
Highlighted
You need to remove users licenses from O365, for that first you need to know which user has which license. If you have only one type of license it shouldn't be difficult to remove them.
First get the license using below:-
Get-MsolAccountSku | Select AccountSkuID
you will get something like yourtenant:EnterprisePack
Now you can use the CSV you have to remove the licenses using:-
Import-Csv C:\Contacts.csv |ForEach{Set-MsolUserLicense -UserPrincipalName $_.UPN -RemoveLicenses "yourtenant:ENTERPRISEPACK " }
Please Note that CSV should have UPNs.

Or you can just delete the user from O365 and let AAD Connect sync the user again.
Highlighted

@DeepakRandhawa  Sorry I am talking about on prem exchange 2013. :)

Highlighted
Okay, this should remove mailboxes
Import-Csv C:\Contacts.csv | ForEach { Disable-Mailbox $_.EmailAddress }
if you are prompted to confirm for every mailbox just add -confirm:$false
Highlighted

@DeepakRandhawa  thanks for this does this also remove the Archive files that are in a separate db?

Highlighted
disabling primary mailbox also disables archive mailbox