Forum Discussion
Is there a way to reset/wipe all data from M365 user accounts in order to re-use the same accounts?
- Mar 24, 2023yes , deleting the users will guarantee what you are trying to achieve , let me know if you need a PowerShell script to create the users based on csv input
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily.
elieelkarkafi that's exactly my question. We can delete all the accounts and set them up again for the next academic year, but we were wondering if we can keep them with all their settings and wipe/remove ONLY the OneDrive/Outlook data. Again, probably deleting and recreating them is the quickest solution...
fstorer you can keep the accounts in the portal and just remove the licenses from them. by removing the license, the user will not have any mailbox in outlook or one drive.
if you want to delete the users from the portal , here a powershell script that you can user that read the users from the CVS file.
#Import the AzureAD module
Import-Module AzureAD
#Set the path of the CSV file containing the list of users to delete
$csvFilePath = "C:\Path\To\Users.csv"
#Get the credentials of an Azure AD administrator account with the necessary permissions to delete users
$adminCreds = Get-Credential -Message "Enter the credentials of an Azure AD administrator with the necessary permissions"
#Connect to Azure AD using the administrator credentials
Connect-AzureAD -Credential $adminCreds
#Read the CSV file and loop through each row
Import-Csv $csvFilePath | ForEach-Object {
#Get the user to delete based on their email address
$user = Get-AzureADUser -Filter "Mail eq '$($_.Email)'"
#Check if the user exists
if ($user) {
#Delete the user
Remove-AzureADUser -ObjectId $user.ObjectId -Force
#Output a message indicating that the user has been deleted
Write-Output "User '$($_.Email)' has been deleted from Azure AD"
}
else {
#Output a message indicating that the user could not be found
Write-Output "User '$($_.Email)' could not be found in Azure AD"
}
}
#Disconnect from Azure AD
Disconnect-AzureAD
- fstorerMar 24, 2023Brass Contributor
elieelkarkafi if I remove the licenses from those accounts and then re-assign them later, will all the previous data in those accounts be accessible again? Or everything is wiped when you remove a Microsoft license?
- Mar 24, 2023When a license is removed from a user, Exchange Online data that is associated with that account is held for 30 days. After the 30-day grace period, the data is deleted and can't be recovered.
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily.- fstorerMar 24, 2023Brass Contributor
elieelkarkafi thanks, I found the https://learn.microsoft.com/en-us/microsoft-365/admin/manage/remove-licenses-from-users?view=o365-worldwide with the information I needed.
I see that
- Files saved in OneDrive for Business aren't deleted unless the user is deleted from the Microsoft 365 admin center or is removed through Active Directory synchronization. For more information, see https://learn.microsoft.com/en-us/onedrive/retention-and-deletion.
So I guess the only solution is still deleting the accounts and then recreating them.