helpers/Connect-O365Sharepoint.ps1

function Connect-O365Sharepoint
{
    PARAM
    (
        [System.Management.Automation.PSCredential]
        $Credential,
        [string]
        $TenantName
    )
    
    try
    {
        Import-Module -Name Microsoft.Online.Sharepoint.Powershell -DisableNameChecking -Force -ErrorAction Stop
    }
    catch
    {
        Write-Error -Message "The module 'Microsoft.Online.Sharepoint.Powershell' was not found. A connection to Sharepoint Online will not be established"
    }

    $Params = @{
        Url = "https://$($PSBoundParameters.TenantName)-admin.sharepoint.com"
        Credential = $Credential
        WarningAction = 'SilentlyContinue'
    }
    Connect-SPOService @Params
}