Here is to connect M365 through the powershell. Installing the module is required. Please always disconnect after you are done doing the task to clear the sesson.
Azure AD
Connect-azureAD # Connect Azure AD
Disconnect-AzureAD # Disconnect Azure AD
Az
Connect-AzAccount # Connect AzAccount
Get-AzSubscription # Check current AZ subscription
Connect-AzAccount # Disconnect AzAccount
Msol
Connect-MsolService # Connect MsolService
[Microsoft.Online.Administration.Automation.ConnectMsolService]::ClearUserSessionState() # Disonnect MsolService
Exchange Online
Connect-ExchangeOnline # Connect ExchangeOnline
Disconnect-ExchangeOnline # Disconnect ExchangeOnline
MS Teams
Install-Module -Name PowerShellGet -Force -AllowClobber
Install-Module -Name MicrosoftTeams -Force -AllowClobber
Alternative:
Install-Module -Name MicrosoftTeams
Update-Module MicrosoftTeams
Connect MS Teams
Connect-MicrosoftTeams
Disconnect MS Teams
Disconnect-MicrosoftTeams