When a Microsoft 365 user account is compromised, you must immediately block the user from signing in. Doing that will also sign out all the user sessions within 60 minutes. In this article, you will learn how to block a Microsoft 365 user sign-in using Microsoft 365 admin center and Microsoft Graph PowerShell.
Table of contents
Microsoft 365 user sign-in blocked
You can block a user from signing in to all Microsoft 365 services in two methods:
- Microsoft 365 admin center
- Microsoft Graph PowerShell
Note: When you block someone, it immediately stops any new sign-ins for that account. If a user is signed in, they will be automatically signed out from all Microsoft services within 60 minutes.
Block user in Microsoft 365 admin center
First, we will show you the steps to block a sign-in in Microsoft 365 admin center for a single user. Then we will show you the steps to block multiple users sign-in.
Block single Microsoft 365 user sign-in
Time needed: 10 minutes.
How to block Microsoft 365 user sign-in.
- Go to Microsoft 365 admin center
Sign in with your admin credentials
- Select the user you want to block.
Click Users > Active users
Select the unblocked user from the list - The user pane opens.
Click Block sign-in
- Block sign-in for user.
Select Block this user from signing in
Click Save changes - The user is now blocked from signing in.
Close the pane
Note: The user will be automatically signed out of all Microsoft services within 60 minutes.
Block multiple Microsoft 365 users
To block multiple Microsoft 365 user accounts, follow these steps:
- Go to Users > Active users
- Select the users in the list
- Click the More button
- Click Edit sign-in status

- Select Block users from signing in
- Click Save

The selected users are blocked from signing in.
Note: The blocked users will not be able to sign in to any Microsoft services, and they will be signed out of all sessions within 60 minutes.
Verify blocked Microsoft 365 user sign-in
To verify you blocked the users, you can filter and find the blocked users in the list.
- Go to User > Active users
- Click Filter > Sign-in blocked

It shows a list of all the sign-in blocked users.

Block user with Microsoft Graph PowerShell
Another way to block a user sign-in is with Microsoft Graph PowerShell. You can use one of the below PowerShell scripts to block a single user or multiple users.
Block single Microsoft 365 user sign-in
- Copy the below PowerShell script into PowerShell ISE or Visual Studio Code
- Change the user principal name (UPN) of the account you want to block on line number 6
- Run the below PowerShell script
# Connect to Microsoft Graph PowerShell
Connect-MgGraph -Scopes Directory.AccessAsUser.All
Select-MgProfile Beta
# Specify the user principal name (UPN) of the account you want to block
$upn = "amanda.hansen@m365info.com"
# Retrieve the user
$user = Get-MgUser -Filter "UserPrincipalName eq '$upn'"
# Check if the user is unblocked
if ($user.AccountEnabled -eq $true) {
# User is unblocked, block the account
Update-MgUser -UserId $User.Id -AccountEnabled:$false
Write-Host "Account $($User.UserPrincipalName) blocked successfully." -ForegroundColor Green
}
else {
Write-Host "Account $($User.UserPrincipalName) is already blocked." -ForegroundColor Cyan
}
The output shows that the user account is blocked.
Welcome To Microsoft Graph!
Account Amanda.Hansen@m365info.com blocked successfully.
If the Microsoft user account were blocked, the output would show that the account is already blocked.
Welcome To Microsoft Graph!
Account Amanda.Hansen@m365info.com is already blocked.
If you like to block multiple users, read the next step.
Block multiple Microsoft 365 users
Follow the below steps to block multiple Microsoft 365 users sign-in with Microsoft Graph PowerShell.
- Create a .txt file and type the user accounts you want to block

- Go to the C:\temp folder
- Name the file
- Save it as a .txt file
- Click Save

- Run the below PowerShell script
# Connect to Microsoft Graph PowerShell
Connect-MgGraph -Scopes Directory.AccessAsUser.All
Select-MgProfile Beta
# Specify the path to the text file containing user principal names (UPNs)
$upns = Get-Content -Path "C:\temp\Users.txt"
# Loop through each UPN in the array
foreach ($upn in $upns) {
# Retrieve the user
$user = Get-MgUser -Filter "UserPrincipalName eq '$upn'"
if ($user) {
# Check if the user is unblocked
if ($user.AccountEnabled -eq $true) {
# User is unblocked, block the account
Update-MgUser -UserId $user.Id -AccountEnabled:$false
Write-Host "Account $($user.UserPrincipalName) blocked successfully." -ForegroundColor Green
}
else {
Write-Host "Account $($user.UserPrincipalName) is already blocked." -ForegroundColor Cyan
}
}
else {
Write-Host "Account $upn not found." -ForegroundColor Yellow
}
}
The output blocks the Microsoft 365 user accounts in the .txt file.
It will not block these user accounts if:
- The user account is already blocked
- The user account does not exist
Welcome To Microsoft Graph!
Account Amanda.Hansen@m365info.com blocked successfully.
Account Amanda.Kent@m365info.com not found.
Account Brenda.Smith@m365info.com is already blocked
Account David.Kent@m365info.com is already blocked
Account Stephen.Hunter@m365info.com blocked successfully.
Verify Microsoft 365 user sign-in blocked
When the blocked user tries to log into Microsoft 365, they will see this warning below.
Your account has been locked. Contact your support person to unlock it, then try again.

You successfully blocked Microsoft 365 user sign-in!
Read more: Change Microsoft 365 tenant display name »
Conclusion
You learned how to block sign-in for Microsoft 365 users. It can be done in Microsoft 365 admin center and with Microsoft Graph PowerShell. To block multiple users, it’s much faster to use a .txt file and run the PowerShell script.
Did you enjoy this article? You may also like Configure technical contact details in Microsoft 365. Don’t forget to follow us and share this article.