forked from timmcmic/DLConversionV2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisable-allPowerShellSessions.ps1
65 lines (49 loc) · 1.86 KB
/
disable-allPowerShellSessions.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<#
.SYNOPSIS
This function disables all open powershell sessions.
.DESCRIPTION
This function disables all open powershell sessions.
.OUTPUTS
No return.
.EXAMPLE
disable-allPowerShellSessions
#>
Function disable-allPowerShellSessions
{
Out-LogFile -string "********************************************************************************"
Out-LogFile -string "BEGIN disable-allPowerShellSessions"
Out-LogFile -string "********************************************************************************"
out-logfile "Gathering all PS Sessions"
try{
$functionSessions = Get-PSSession -errorAction STOP
}
catch
{
out-logfile -string "Error getting PSSessions - hard abort since this is called in exit code."
EXIT
}
out-logFile -string "Disconnecting Exchange Online Session"
foreach ($session in $functionSessions)
{
if ($session.computerName -eq "outlook.office365.com")
{
try{
Disconnect-ExchangeOnline -confirm:$FALSE -errorAction STOP
}
catch{
out-logfile -string "Error removing Exchange Online Session - Hard Exit since this function is called in error code."
EXIT
}
}
}
out-logfile -string "Remove all other PSSessions"
try{
Get-PSSession | remove-pssession
}
catch{
out-logfile -string "Error removing other PS Sessions. Hard exit as this function is called in error code."
exit
}
Out-LogFile -string "END disable-allPowerShellSessions"
Out-LogFile -string "********************************************************************************"
}