Contents

Connect to Office 365 with PowerShell

You are here:
← All Topics

Steps on how to connect to Office 365 with PowerShell

  1. Go to Office 365 DEMO and sign up for 90 Days Trial Account with your Microsoft Partner Login

  2. Download and install Microsoft Online Services Sign-in Assistant for IT Professionals RTW-msoidcli_64.msi

  3. Install MSOnline Module

Install-Module MSOnline

Connect using MSOnline Module

Prepare the saved Credential for automate login in the future

$UserName = "[email protected]"
#Replace XXXX with Actual Password
"XXXXX" | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString | Out-File "C:\scripts\Password.txt"
$Password = Get-Content "C:\Scripts\Password.txt" | ConvertTo-SecureString

#Specify Credential with password 
$Credential = new-object -typename System.Management.Automation.PSCredential -ArgumentList $UserName,$Password

#Login to Office 365
Connect-MsolService -Credential $Credential

Connect using AzureAD Module

Install-Module -Name AzureAD

Import-Module AzureAD

$KeyFile = "C:\O365-AventisLab\MasterKey.key"
$PasswordFile = "C:\O365-AventisLab\Password-AventisLab.txt"

$Password = Get-Content $PasswordFile | ConvertTo-SecureString -Key (Get-Content $KeyFile)
$UserName = "[email protected]" 
$credential = New-Object System.Management.Automation.PsCredential($UserName,$Password)

Connect-AzureAD -Credential $Credential

Connect to Exchange Online

Login to Exchange Online

#Change the Execution Policy to RemoteSigned 
Set-ExecutionPolicy RemoteSigned -Force #First Time only 

$Session_EX = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ `
-Credential $Credential -Authentication  Basic -AllowRedirection

Import-PSSession $Session_EX

Reference links

https://docs.microsoft.com/en-us/office365/enterprise/powershell/connect-to-office-365-powershell

Connect to Exchange Online with MFA enabled user account

Install ExchangeOnlineManagement Module

Install-Module -Name ExchangeOnlineManagement

Login to MSOL and Exchange Online

#Login to O365 using account with MFA enabled 
Connect-MsolService -Credential $Credential

#Login to Exchange Online with MFA Enabled with EXO v2

Import-Module ExchangeOnlineManagement

$UserName = "[email protected]"
Connect-ExchangeOnline -UserPrincipalName $UserName -ShowProgress $true

Connect to Security & Compliance Center

No additional module is required to connect

#Connect to Security & Compliance Center
$Session_SCC = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.compliance.protection.outlook.com/powershell-liveid/ `
-Credential $Credential -Authentication Basic -AllowRedirection

Import-PSSession $Session_SCC

Connect to SharePoint Online & OneDrive

Install SharePoint Online Module

Install-Module -Name Microsoft.Online.SharePoint.PowerShell

Connect to SharePoint Online with Office 365 Tenant Name (AventisTech.onmicrosoft.com)

$TenantName="AventisTech"
Connect-SPOService -Url https://$TenantName-admin.sharepoint.com -Credential $Credential

Connect to Microsoft Team

Two different PowerShell modules are required

  1. Microsoft Team PowerShell Module – contains all the cmdlets you need to create and manage teams.
#Install Microsoft Team PowerShell Module
Install-Module -Name MicrosoftTeams
  1. Skype for Business PowerShell Module – contains the cmdlets to manage policies, configurations, and other Teams tools.

Connect to Microsoft Team

Connect-MicrosoftTeams -Credential $credential

Account      : [email protected]
Environment  : AzureCloud
Tenant       : bbexxxxxxxxxxxxxxxxxxxxxx
TenantId     : bbexxxxxxxxxxxxxxxxxxxxx
TenantDomain : aventistech.com

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top