Disabling a user
This recipe explains how to disable a user in your Microsoft 365 tenant using the Microsoft Graph PowerShell SDK. Disabling a user is helpful for temporarily blocking sign-in to manage user access and security within your organization, such as when an employee may be on extended leave. Disabling a user may also be useful when an employee separates from your company but you don’t want to delete the account entirely yet.
Getting ready
Follow the guidance in the Setting up PowerShell recipe from Chapter 1, Microsoft 365 Setup and Basic Administration, to connect to your Microsoft 365 tenant via PowerShell. Ensure you have administrative privileges on your system, as well as administrative permissions to modify user profiles in your Microsoft 365 tenant such as User Administrator or Global Administrator.
How to do it…
Run the following command to disable a user account by setting the AccountEnabled
property to $false
:
Update-MgUser -UserId...