Home / Blog / Exchange Online
PowerShell Basics for Office 365 Administration (Episode 2)
Choose the module for the task before opening a session. This walkthrough covers the connection you need for directory queries and the separate connection used for Exchange administration.
Install the modules you need
For directory users, start with Microsoft Graph. Use ExchangeOnlineManagement for mailbox administration. Install the modules under the account that will run the examples.
Install-Module Microsoft.Graph.Users -Scope CurrentUser
Install-Module ExchangeOnlineManagement -Scope CurrentUserRead a directory user
Sign in to the intended tenant. For this delegated example, request the permission that lets you read basic profiles. Your organization’s consent policy still applies.
Connect-MgGraph -Scopes "User.ReadBasic.All"
Get-MgContext | Select-Object Account, TenantId, Scopes
Get-MgUser -Top 5 | Select-Object DisplayName, UserPrincipalNameRead a mailbox
Connect separately to Exchange Online with an account that can read mailbox information. The Graph connection does not grant Exchange PowerShell permissions.
Connect-ExchangeOnline
Get-EXOMailbox -ResultSize 5 | Select-Object DisplayName, PrimarySmtpAddressClose the sessions
Disconnect-ExchangeOnline -Confirm:$false
Disconnect-MgGraphIf an older script uses Connect-MsolService or Connect-AzureAD, identify the operation and migrate it before running the script. Neither legacy module is a prerequisite for the exercises here.