PowerShell

Here is some (useful) information regarding PowerShell and:

  • Exchange Server
  • Exchange Online
  • Entra ID

Exchange Server

You can use the Exchange Management Shell, but you can also open a regular PowerShell window and use the following commands to connect to an Exchange server. This is the official way.

$Credential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://+([System.Net.DNS]::GetHostByName(($ENV:ComputerName))).HostName+"/PowerShell" -Authentication Kerberos -Credential $Credential
Import-PSSession $Session -AllowClobber

Another option is load the PowerShell snap-in directly into your session. Use the following command for Exchange 2010:

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
And use the following command for Exchange 2013 and up:
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Snapin

The first option also respects RBAC roles, so only PowerShell commands that you are allowed to use are available. In the second option all commands are available, but they may fail because of permission restrictions. Another thing to be aware of that the Exchange Management Shell will sometimes return values in a different way than PowerShell with the PS snap-in will (Get-MailboxStatistics for example).

Exchange Online

Microsoft has stopped support for Basic Authentication in Exchange Online, so you can no longer use the New-PSSession command in Exchange Online. Instead you must use the Exchange Online Management module in PowerShell.

To install the Exchange Online Management module, execute the following command in a PowerShell window:

Install-Module ExchangeOnlineManagement -RequiredVersion 3.8.0

For more information about versioning, check the PowerShell Gallery on https://www.powershellgallery.com/packages/ExchangeOnlineManagement

Entra ID

You can install the Microsoft Entra PowerShell module to manage Entra ID using PowerShell. Use the following command to install the Entra PowerShell module:

Install-Module -Name Microsoft.Entra -Repository PSGallery -Scope CurrentUser -Force -AllowClobber

This will install all available Entra modules. If you want to install only a subset of the modules, for example only for users, you can use the following example:

Install-Module -Name Microsoft.Entra.Users -Repository PSGallery -Force -AllowClobber

To login into Entra ID use the following example:

Connect-Entra -Scopes 'User.Read.All'

More information can be found here.

Microsoft Graph

The way ahead is Microsoft Graph.

PowerShell filtering

Exchange Filterable Properties – https://learn.microsoft.com/en-us/powershell/exchange/filter-properties?view=exchange-ps

User -Filter option instead of Where funtion (which retrieves all objects first, where -Filter only returns the objects you need)

Get-Mailbox -Filter 'RecipientTypeDetails -eq "RoomMailBox"'

page last updated: May 23, 2025