-
Notifications
You must be signed in to change notification settings - Fork 237
/
mggraph-disconnect.ps1
48 lines (38 loc) · 1.5 KB
/
mggraph-disconnect.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
39
40
41
42
43
44
45
46
47
48
param(
[switch]$debug = $false ## if -debug parameter don't prompt for input
)
<#CIAOPS
Script provided as is. Use at own risk. No guarantees or warranty provided.
Description - Disconnect from the Mirosoft Graph
Source - https://github.com/directorcia/Office365/blob/master/mggraph-disconnect.ps1
Prerequisites = 1
1. Ensure Microsoft.Graph module is loaded
#>
## Variables
$systemmessagecolor = "cyan"
$processmessagecolor = "green"
$errormessagecolor = "red"
$warningmessagecolor = "yellow"
## If you have running scripts that don't have a certificate, run this command once to disable that level of security
## set-executionpolicy -executionpolicy bypass -scope currentuser -force
Clear-Host
if ($debug) {
write-host "Script activity logged at ..\mggraph-disconnect.txt"
start-transcript "..\mggraph-disconnect.txt" | Out-Null ## Log file created in parent directory that is overwritten on each run
}
write-host -foregroundcolor $systemmessagecolor "Microsoft Graph disconnect script started"
write-host -foregroundcolor $processmessagecolor "`nDisconnect any existing Graph sessions"
try {
Disconnect-MgGraph -erroraction stop | Out-Null
}
catch {
Write-Host -ForegroundColor $errormessagecolor "`n", $_.Exception.Message,"`n"
if ($debug) {
Stop-Transcript | Out-Null
}
exit 1
}
Write-Host -ForegroundColor $systemmessagecolor "`nMicrosoft Graph disconnect script finished`n"
if ($debug) {
Stop-Transcript | Out-Null
}