How to connect to O365 using PowerShell

PowerShell is a necessary tool  to connect to O365 administration, more than the 40% of the features of O365 are not visible in the administration panel, so the only way to manage them is via PowerShell code. To the vast majority of users the web portal will be more useful, but if you need to do repetitive tasks or very complex PowerShell is your tool.

So, how do we connect to the several services that offer O365? Let’s being:

Azure Active Directory

$credential = get-credential
Import-Module MsOnline

Connect-MsolService -Credential $credential

Exchange Online

$exchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $credential -Authentication “Basic” -AllowRedirection

Import-PSSession $exchangeSession

SharePoint Online

Import-Module Microsoft.Online.SharePoint.PowerShell

Connect-SPOService -Url https://<NombreDelTenant> -credential $credential

Skype for Business

Import-Module LyncOnlineConnector

$lyncSession = New-CsOnlineSession -Credential $credential

Import-PSSession $lyncSession

BONUS: Microsoft Azure

Get-AzurePublishSettingsFile cmdlet

#opens a web page on the Windows Azure Management Portal, from which you can download the subscription information. The information is contained in a .publishsettings file.

Import-AzurePublishSettingsFile “Pathtopublishingfile”


#the previous commands allow to view account and subscription details

Depending of which operations or services we are using, we will be able to connect to the service without problem


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s