Permanently delete users mailbox and archive mail boxes

Brass 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
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.

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

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

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

disabling primary mailbox also disables archive mailbox