In this tutorial, we will show how to connect to your Office 365 Exchange via PowerShell.
Prerequisites:
- Account must be a member of the organizations global admin group
- Download and install the following PowerShell modules from Microsoft
- Microsoft Online Services Sign-In Assistant for IT Professionals RTW
- Install the Microsoft Azure Active Directory Module by running the following command within PowerShell:
- Install-Module -Name AzureAD
- If prompted about installing a module from an untrusted repository, type Y and press ENTER.
- Microsoft .Net framework 4.5.X and above
Once the prerequisites have been completed, run the following:
$Credential = Get-Credential
Enter your Office 365 admin credentials and hit OK. This inputs your credentials into a variable named "Credential" and will be called on in the next step.
Next, enter the following command:
$Session = New-PSSession -ConfigurationName Microsoft.Exchange - ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Credential -Authentication Basic -AllowRedirection
After this command has been run, run the last command:
Import-PSSession $Session
If this is the first time making an Office365 connection with PowerShell, you will need to set the execution policy:
If this is the first time making an Office365 connection with PowerShell, you will need to set the execution policy:
set-ExecutionPolicy remotesigned
And that is it. To test the connection, simply run the Get Mailbox command:
get-mailbox
It is also a good habit to close your active PowerShell connection. Run this to close the active session:
It is also a good habit to close your active PowerShell connection. Run this to close the active session:
Remove-ActiveSession $PSSession
No comments:
Post a Comment