Posted On November 18, 2019

PowerShell: How to Properly Delete a Msol User Account

kimconnect 0 comments
blog.KimConnect.com >> Codes >> PowerShell: How to Properly Delete a Msol User Account
# Set the user ObjectID attribute variable
$msolUser="6f2fcfcd-...."

# Move user account to Recycle Bin
Remove-MsolUser -ObjectId $msolUser

# Purge from Recycle Bin
Get-MsolUser -ObjectID $msolUser -ReturnDeletedUsers | Remove-MsolUser -RemoveFromRecycleBin

# Remove from contacts bin
Get-MsolContact -ObjectID $msolUser | FL #Validate that this is a correct account
Get-MsolContact -ObjectID $msolUser | Remove-MsolContact

# Optional: if object is a group instead of a user
Get-MsolGroup -ObjectID $msolUser | Select EmailAdress,ProxyAddresses #Validate that this is the correct account
Get-MsolGroup -ObjectID $msolUser | Remove-MsolGroup

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

PowerShell: Copy SMB Share Permissions from Legacy Sources

Scenario:Windows 2008 File Servers migration lacks a built-in function to clone Share Permissions - Get-SmbShareAccess…

PowerShell: Remove an A-Host Record within Active Directory Integrated DNS Domain

Warning: this code is NOT 'production ready'. Please review and test on DEV environments carefully…

PowerShell: Accessing the Reflection Assembly Class to Retrieve User Context

Step 1: Accessing Reflection Assembly namespace to call method Load with Windows Account Management as…