Inicio > English Articles, Office365, Powershell > Purge deleted users in Office365

Purge deleted users in Office365

miércoles, 6 de noviembre de 2013 Dejar un comentario Ir a comentarios

Cambiar-idioma-esp

branding

When we delete a user in Office365 this isn´t deleted as well because it gets sent to a recycle binfor 30 days (Soft-Delete). This can be good when we want to restore it with all the permissions, content and details, but what happens when the user John Smith leaves the company and some days further another user named Judy Smith gets incorporated to the company as well? If we would like to assign the new username following the org policy Initial.LastName (J.Smith) for example, we will encounter that Office365 will Return an error saying it cannot create the user because the username already exists.

To force the deletion of the user from the recycle bin, we must do it with the use of PowerShell.

To do so, we must get our environment prepared for PowerShell and Office365.

First we must signin to our Office365 subscription with the use of the following CmdLets:

$LiveCred = Get-Credential 

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection

Import-PSSession $Session

Import the Online Services module:

Import-Module MSOnline

 

Run the following CmdLet to get the ObjectId of the user to be deleted:

Get-MsolUser -All -ReturnDeletedUsers|select userprincipalname,objectid

Finally execute the purge of the desired user with the ObjectId obtained before:

Remove-MsolUser -ObjectId «objectid» -RemoveFromRecycleBin -Force

 

Hope it helps someone.

 

 

  1. Sin comentarios aún.
  1. miércoles, 6 de noviembre de 2013 a las 09:37 | #1
  2. miércoles, 6 de noviembre de 2013 a las 13:57 | #2
  3. martes, 10 de diciembre de 2013 a las 09:01 | #3
Debes estar registrado para dejar un comentario.