-
Notifications
You must be signed in to change notification settings - Fork 8
/
End-O365Sessions.ps1
38 lines (31 loc) · 1.07 KB
/
End-O365Sessions.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File: End-O365Sessions.ps1
# Purpose: this script will use all available methods to end all sessions of a
# specific user as soon as possible. Unfortunately, it may take up to an hour
# for some sessions on some devices to be effectively terminated.
#
# Copyright (c) 2019, jdgregson
# Author: Jonathan Gregson <[email protected]>
Param (
[Parameter(Mandatory=$true)]
[string]
$User,
[int]
$Attempts = 100,
[string]
$CredFile,
[switch]
$Prompt
)
# connect to Azure AD and SharePoint Online Administration
. "$PSScriptRoot\O365-Auth.ps1"
if (($prompt -and (O365-Auth -Azure -SharePointAdmin -Prompt) -eq 1) -or (O365-Auth -Azure -SharePointAdmin) -eq 1) {
Write-Warning "Failed to authenticate with Office 365"
Exit
}
Write-Host "Attempting to end all sessions $Attempts times..."
while ($Attempts -gt 0) {
Revoke-SPOUserSession -User $User -Confirm:$False -WarningAction "SilentlyContinue"
Get-AzureAdUser -SearchString $User | Revoke-AzureADUserAllRefreshToken
$Attempts--
}