Because I’m testing I made this, so I dont need to fill in everytime the credentials, but checks if there is a connection.

AzureAD Connect

if($azureConnection.Account -eq $null){
$azureConnection = Connect-AzureAD
}

MSO Connect Check

if( $credential -eq $null){
$credential = Get-Credential
Connect-MsolService -Credential $credential
}