Export Blocked Office 365 Users to CSV using PowerShell

Getting list of sign-in blocked Azure AD users is one of the important task for every Office 365 admin to decide whether we are spending our license for valid user accounts or not. We can use the Azure AD powershell cmdlet Get-MsolUser to find and get a list of Office 365 users who are blocked to login into Office 365 service (Ex: Mailbox, Teams, Planner, SharePoint, etc).


Note: Before proceed, Install and Configure Azure AD PowerShell

Summary

Find and List Blocked Users

The Get-MsolUser cmdlet returns all the Azure AD users and we can apply the Where filter with parameter BlockCredential to get only sign-in blocked users.

Get-MsolUser -All | Where {$_.BlockCredential -eq $True} | Select DisplayName,UserPrincipalName

Export Blocked Users to CSV

Run the below command to export all the users who have been blocked to login into Office 365 services.

Get-MsolUser -All | Where {$_.BlockCredential -eq $True} |
Select DisplayName,UserPrincipalName, IsLicensed |
Export-CSV "C:\Blocked_Users.csv" -NoTypeInformation -Encoding UTF8

Export Licensed and Blocked Users to CSV

Normally we will block access to the users who are leaving office or terminated employees, once we blocked access to Office 365 service the next step is to remove existing license subscriptions from blocked users, so we need to get a list of users who are licensed and blocked to login into Office portal. Run the following command to export all the licensed users who have been blocked.

Get-MsolUser -All | Where {$_.IsLicensed -eq $True -AND $_.BlockCredential -eq $True} |
Select DisplayName,UserPrincipalName, BlockCredential |
Export-CSV "C:\Blocked_Licensed_Users.csv" -NoTypeInformation -Encoding UTF8

Note: Checkout this post : Manage Office 365 License using Powershell to add a new license, remove an existing license and update existing license subscription using PowerShell command.

Advertisement

2 thoughts on “Export Blocked Office 365 Users to CSV using PowerShell”

Leave a Comment