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 https://yourdomainname-admin.sharepoint.com -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.

Advertisements

About pgbhoyar

Prashant G Bhoyar is a Microsoft Office Server & Services MVP and Microsoft Certified Professional. He currently works as a Senior Consultant at WithumSmith+Brown, PC. He is a trusted adviser and Subject Matter Expert and specializes in the development and post-implementation adoption of complex custom solutions in Office 365 and SharePoint. Prashant has supported many government agencies and non-profit organizations in the Washington D.C. metropolitan area. Prashant was the technical reviewer of the book "Pro SharePoint 2013 Administration." He serves on the leadership committee for the DC Metro Office 365 User Group and SharePoint Saturday Baltimore event and SharePoint Saturday Washington DC event. He actively speaks at technical conferences across the country, most recently in New Orleans, Chicago, Houston, Seattle, Baltimore, Philadelphia, as well as, at many events throughout North America. 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 Uncategorized, Office 365, Office365 OWA, Office 365 OWA, SharePoint Online, Office 365 Group, Office 365 Unified Group, Outlook 2016, PowerShell for Office 365, Exchange Online and tagged , , , , . Bookmark the permalink.

Leave a Reply

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

WordPress.com Logo

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

Google+ photo

You are commenting using your Google+ 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 )

w

Connecting to %s