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

SQL Failover (Simple Method)

$servers="SQL01","SQL02","SQL03"; # Dynamic Credential method 1 $who = whoami if ($who.substring($who.length-2, 2) -eq "-admin"){$username=$who;} else…

Java Virtual Machine Optimal Memory Tuning

Overview: There are five available garbage collectors (GC) for Java Virtual Machines (JVM). Here are…

PowerShell: Chicken Scratch Ports Scanner

Although there are optimized applications to perform this task such as Angry Port Scanner, NMAP,…