helpers/Connect-O365AzureAD.ps1

function Connect-O365AzureAD
{
    <#
        .NOTES
        Currently supports the MSOnline module - should eventually support the AzureAD module as well, and will check to see which one is installed. If both, then AzureAD will be preferred.
    #>

    PARAM
    (
        [System.Management.Automation.PSCredential]
        $Credential
    )

    try
    {
        Import-Module -Name MSOnline -DisableNameChecking -Force -ErrorAction Stop
    }
    catch
    {
        Write-Error -Message "The module 'MSOnline' was not found. A connection to Azure Active Directory will not be established"
    }
    Import-Module -Name MSOnline -DisableNameChecking -Force
    Connect-MsolService -Credential $Credential
}