public/Test-O365Connection.ps1

<#
.Synopsis
This powershell cmdlet tests whether or not you are connected to Office 365 for powershell management of the system. If you are not connected, it will automatically connect your powershell session to Office 365.
  
.Description
Tests your connection to Office 365 and establishes a connection if it finds you are not connected.
  
.Example
Test-O365Connection
#>


Function Test-O365Connection{
Get-MsolDomain -ErrorAction SilentlyContinue | out-null
$result = $?

    switch ($result)
        {
        False { Write-Host 'Not connected to O365 Account, initiating connection'
                Connect-O365Tools
                }
        True {return}
        }
}