Wednesday, August 16, 2017

Remove-O365PSSession.ps1

Today's script does some basic house cleaning when closing Office 365 Sessions.

As script is simple now code break down unless I receive requests.


 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
<#
.SYNOPSIS
    Remove open O365 PSSessions
.DESCRIPTION
    Remove open O365 PSSessions
.EXAMPLE
    Remove-O365PSSession.ps1
.NOTES
    Created by Chris Lee
    Date April 20, 2017
.LINK 
    GitHub: https://github.com/clee1107/Public/blob/master/O365/Remove-O365PSSession.ps1
    Blogger:http://www.myitresourcebook.com/2017/08/httpsgithubcomclee1107publicblobmastero.html
#>

#################################
## DO NOT EDIT BELOW THIS LINE ##
#################################

##Close open All O365 product Sessions
Write-Verbose -Message "Removing all PSSessions"
Get-PSSession | Remove-PSSession
Write-Verbose -Message "Disconnecting SharePoint Online"
$ExitPowershell = Read-Host -Prompt "Disconnect from O365 (Will close current Powershell Window) [Y]/N"
If ($ExitPowershell -eq "Y" -OR $ExitPowershell -eq $null -OR $ExitPowershell -eq "")
    {
        stop-process -Id $PID
    }


Full script can be accessed from following link:
https://github.com/clee1107/Public/blob/master/O365/Remove-O365PSSession.ps1
Further reference links for PowerShell cmdlets used can be found on following post:

Code Snippets created via: http://hilite.me/

No comments:

Post a Comment