Block Microsoft 365 User Using Microsoft Graph PowerShell

A step-by-step guide to teach you how to use PowerShell to block a user from logging in and accessing Microsoft 365 services.

Blocking a user in Microsoft 365 (Office 365) from signing in can be an effective way to restrict access without directly modifying user passwords or deleting accounts. This can be done easily using Microsoft Graph API via PowerShell.

Step 1: Install the Microsoft Graph PowerShell Module

Run Install-Module -Name Microsoft.Graph -Scope CurrentUser command to install Microsoft Graph PowerShell module.

Step 2: Authenticate

You must authenticate to Microsoft Graph with the required permission User.ReadWrite.All.

Connect-MgGraph -Scopes "User.ReadWrite.All" is the command.

Step 3: Identify the User

Find the user you want to block. You can identify them by their user principal name (UPN), email, or object ID.



Step 4: Block the User

To block the user, you’ll need to disable their sign-in status. This can be done by setting the accountEnabled parameter to $false. This doesn't delete the user or their data but prevents them from signing in.


Unblocking the Blocked User Account

To unblock the user, you’ll need to enable their sign-in status. This can be done by setting the accountEnabled parameter to $true

Note: Read Microsoft Documentation on Blocking Microsoft 365 user accounts using Graph PowerShell for more information.


Related Articles:

Using Get-MgDirectoryRole in Graph PowerShell
Using Get-MgUserLicenseDetail in Graph PowerShell
Using Find-GraphMgCommand in Graph PowerShell
Connect to Microsoft 365 Using PowerShell
Create Microsoft 365 Group Using Microsoft Graph PowerShell
Assign Microsoft 365 License Using Graph PowerShell
Microsoft 365 User Management Using Graph PowerShell
Checking Group Membership in Microsoft 365
Bulk Assign Microsoft 365 License
Find Inactive Users in Microsoft 365
Using Powershell Graph Search Query
Using Powershell Graph Filter Query
Using Where-Object In Graph PowerShell
Using Expand Property In Graph PowerShell
Using Select Object In Graph PowerShell
Using -Contains Operator In Graph PowerShell
Add User to Multiple Microsoft 365 Groups Using Graph PowerShell
Get Microsoft 365 User Location Using Graph PowerShell
Import Microsoft 365 Groups from CSV File Using Graph PowerShell
Microsoft 365 Group User Import Using Graph PowerShell

© m365corner.com. All Rights Reserved. Design by HTML Codex