PowerShell: Connect to Office 365


People hi,


When I haven’t my script to connect automatically to Office 365, I lose 5-10 minutes to find the modules and the cmdlets.

So, a quick note for myself 🙂



To be able to use the Office365/MSOL PowerShell features, you should have:

  • Microsoft .NET Framework 4.5 ou 4.5.1
  • Windows Management Framework 3.0 or Windows Management Framework 4.0 (to install directly on your computer by Programs and Features)
  • Microsoft Online Services Sign-In Assistant(Lien)
  • Azure Active Directory module for PowerShell


$adminCredential = Get-Credential

## Note: We are able to inform the user credential in the cmdlet:
$adminCredential = Get-Credential -credential "p.Pomme@BachToTheCloud.com"

## If you are using a Proxy, you should use this feature ; )
$proxySettings = New-PSSessionOption -ProxyAccessType IEConfig

## Creation of the remote session in a $variable:
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $adminCredential -Authentication Basic –AllowRedirection

## Import of the PowerShell session:
Import-PSSession $Session

## Connection to the MSOL service:
Connect-MsolService -Credential $adminCredential


Now, you are able to play on your tenant 😉

Remove-PSSession $session 

More information or sources:

To install .NET Framework 4.5, 4.5.1 and 4.5.2 http://msdn.microsoft.com/library/5a4x27ek(VS.110).aspx

Technet about Azure Active Directory https://docs.microsoft.com/en-us/powershell/msonline/v1/azureactivedirectory?redirectedfrom=msdn#bkmk_installmodule

1 Comment

Leave a Reply