Office 365: How to force log out multiple users using PowerShell Script?

To force log out users, we can use the Office 365 Admin Center or PowerShell.

In Office 365 Admin center, use the following the following steps.

  1. Office 365 Admin Center
  2. Users -> Active Users ->Select the User and in the OneDrive settings, click Initiate sign out.

If you would like to force sign out multiple users, you can also execute following script.

Import-Module MSOnline
$cred = Get-Credential
Connect-MsolService -Credential $cred
Connect-SPOService -Url -Credential $cred

# To get all enabled users
#$users = Get-MsolUser -EnabledFilter EnabledOnly -All

# To get all the users of a Department
#$users = Get-MsolUser -Department ‘Department Name’ -All

# To get all the users
$users = Get-MsolUser -All;

foreach ( $user in $users){
Revoke-SPOUserSession -user $user.UserPrincipalName -Confirm:$false

Security Requirements: You need to be a SharePoint Online Global administrator to run the cmdlet Revoke-SPOUserSession.

The user will be signed out from all the sessions across all the devices.

It may take up to an hour for all sign-outs.

Note: If this is the first time you are running the PowerShell for Office 365, use the following two links to install the required tools.

  1. Connect to Office 365 PowerShell
  2. SharePoint Online Management Shell

Please post in the comments section, if you have more ideas for scripts.

About pgbhoyar

Prashant G Bhoyar is a Microsoft AI MVP and Microsoft Certified Professional. He currently works as a Senior Solution Architect at WithumSmith+Brown, P.C. (formerly Portal Solutions), one of the top 30 advisory and accounting firms in the United States. He is a trusted advisor and Subject Matter Expert in Intelligent Business Process Automation, development and post-implementation adoption of complex custom solutions in AI, Machine Learning, Bots, Azure, Office 365, and SharePoint. Prashant has supported a multitude of government agencies and non-profit organizations in the Washington D.C. metropolitan area. Prashant is the co-author of the book “PowerShell for Office 365 “and is the technical reviewer of the book "Pro SharePoint 2013 Administration." He serves on the leadership committee for the Azure Data Fest conference, Artificial Intelligence Fest conference, Artificial Intelligence and Machine Learning User Group, DC Metro Office 365 User Group, SharePoint Saturday Baltimore event, and SharePoint Saturday Washington DC event. He is a renowned international speaker and actively speaks at technical conferences, most recently in India, Canada, England, Bangladesh, Peru , Washington DC, Austin, New York, Chicago, Seattle, New Orleans, Baltimore, Philadelphia. Fun fact??, Prashant is a recipient of the "Antarctic Service Medal of the United States of America" for his outstanding service in Antarctica.
This entry was posted in Exchange Online, Office 365, Office 365 Group, Office 365 OWA, Office 365 Unified Group, Office365 OWA, Outlook 2016, PowerShell for Office 365, SharePoint Online, Uncategorized and tagged , , , , . Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s