Scripts/get-connected.ps1

function Get-Connected {

    param (
        [parameter(Mandatory = $true)]
        $username
        ,
        [parameter(Mandatory = $true)]
        $password
    )

    $SecurePassword = ConvertTo-SecureString $password -AsPlainText -Force
    $credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $SecurePassword
    Connect-MsolService -Credential $credential
    Connect-AzureAD -Credential $credential
    Connect-MicrosoftTeams -Credential $credential
}

function Get-ConnectedMFA {
    write-host "Connecting to 365 Powershell..." -ForegroundColor Green
    Connect-MsolService
    Write-Host "Connecting to AzureAD Powershell..." -ForegroundColor Green
    Connect-AzureAD
    Write-Host "Connecting to Microsoft Teams Powershell..." -ForegroundColor Green
    Connect-MicrosoftTeams
}

function Disconnect-Sessions {
    Disconnect-MicrosoftTeams
    Disconnect-AzureAD
    [Microsoft.Online.Administration.Automation.ConnectMsolService]::ClearUserSessionState()
    Get-PSSession | Remove-PSSession
}