Haven’t you heard? Basic auth is dead. Or at least dying. Not only should you switch to modern authentication for Exchange Online, but you should be using the Exchange Online PowerShell V2 Module. Per Microsoft, “The module contains a small set of exclusive Exchange Online PowerShell cmdlets that are optimized for bulk data retrieval scenarios (think: thousands and thousands of objects)”. Also, older cmdlets still work. See here for the full list of EXO V2 cmdlets.

Install or Update

# Check to see if you have the EOM Module installed already
Import-Module ExchangeOnlineManagement; Get-Module ExchangeOnlineManagement

# If yes, update it
Update-Module -Name ExchangeOnlineManagement -Scope CurrentUser

# If no, install it
Install-Module -Name ExchangeOnlineManagement -Scope CurrentUser

# Confirm installed
Import-Module ExchangeOnlineManagement; Get-Module ExchangeOnlineManagement

Connect

Connect-ExchangeOnline -UserPrincipalName username@domain.com -ShowProgress $true

That’s it. We are now connected to EXO using modern authentication. We are also using the latest module and can use the new Get-EXO cmdlets. Below are some basics for managing an O365 environment. Some are exclusive to EXO V2 and some are not. Enjoy!

Microsoft 365 Groups

# Get info about M365 Group
Get-UnifiedGroup -Identity "Legal Department" | Format-List

# Add member(s)
Add-UnifiedGroupLinks -Identity "Legal Department" -LinkType Members -Links chris@contoso.com,michelle@contoso.com -confirm

# Add owner(s)
Add-UnifiedGroupLinks -Identity "Legal Department" -LinkType Owners -Links chris@contoso.com,michelle@contoso.com -confirm

# Remove member(s)
Remove-UnifiedGroupLinks -Identity "People Leaders" -LinkType Members -Links laura@contoso.com,julia@contoso.com -confirm

# Remove owner(s)
Remove-UnifiedGroupLinks -Identity "People Leaders" -LinkType Owners -Links laura@contoso.com,julia@contoso.com -confirm

# Create new
New-UnifiedGroup -accesstype Private -AutoSubscribeNewMembers -DisplayName "Group Name" -EmailAddresses groupname@contoso.com -Owner julia@contoso.com -Members chris@contoso.com,michelle@contoso.com -notes "Requested by Susan Suzzy"

# Add authorized sender(s)
Set-UnifiedGroup -Identity  "Group Name" -AcceptMessagesOnlyFrom @{add="email@contoso.com"} -confirm

# Auto subscribe new members
Set-UnifiedGroup -Identity  "Group Name" -AutoSubscribeNewMembers:$true

# Hide from GAL
Set-UnifiedGroup -Identity  "Group Name" -HiddenFromAddressListsEnabled:$true

Microsoft 365 Group Common Commands and References

Get-UnifiedGroup, Add-UnifiedGroupLinks, Remove-UnifiedGroupLinks, New-UnifiedGroup, Set-UnifiedGroup

Dynamic Distribution Lists

# List all dynamic distros
Get-DynamicDistributionGroup

# Get info about a specific dynamic distro
Get-DynamicDistributionGroup -Identity "all-Company" | Format-List

# list all members of a dynamic distro
$DD = Get-DynamicDistributionGroup "all-Company"; Get-Recipient -RecipientPreviewFilter $DD.RecipientFilter -OrganizationalUnit $DD.RecipientContainer

# Change A DD filter
Set-DynamicDistributionGroup -Identity "all-Company" -RecipientFilter "((RecipientType -eq 'UserMailbox') -and (Office -eq 'Main Office'))"

# Pull all members
$DD = Get-DynamicDistributionGroup "all-Company"
Get-Recipient -ResultSize Unlimited -RecipientPreviewFilter $DD.RecipientFilter -OrganizationalUnit $DD.RecipientContainer | Format-Table Name,Primary*

Dynamic Distribution List Common Commands and References

Get-DynamicDistributionGroup, Set-DynamicDistributionGroup

Calendar Permissions

# View current permissions for user's calendar
Get-MailboxFolderPermission -Identity user@domain.com:\Calendar | ft Identity,FolderName,User,AccessRights,SharingPermissionFlags

# Set user to have Editor permissions to user's calendar | Note that Delegate will be able to do everything except view private events
# Note that -SendNotificationToUser is true and the person will get an email to accept the permissions
Set-MailboxFolderPermission -Identity user@domain.com:\Calendar -User user@domain.com -AccessRights Editor -SharingPermissionFlags Delegate -SendNotificationToUser $true

# Remove permissions
Remove-MailboxFolderPermission -Identity user@domain.com:\Calendar -User user@domain.com

Calendar Permissions Common Commands and References

Get-MailboxFolderPermissions, Set-MailboxFolderPermission, Remove-MailboxFolderPermission

Cleanup a Mailbox

# Simple mailbox check for size
Get-EXOMailboxStatistics -Identity john@contoso.com | Format-Table Name,DeletedItemCount,ItemCount,TotalDeletedItemSize,TotalItemSize

# Another query for mailbox statistics
Get-EXOMailboxFolderStatistics mailboxname@contoso.com -FolderScope RecoverableItems | Format-Table Name,FolderAndSubfolderSize,ItemsInFolderAndSubfolders

# Check mailbox retention for deleted items
Get-EXOMailbox mailboxName@contoso.com | Format-Table RetainDeletedItemsFor
# Set the mailbox retention
Set-Mailbox mailboxName@contoso.com -RetainDeletedItemsFor 30

# Check ELC status
Get-EXOMailbox mailboxName@contoso.com | Format-Table ElcProcessingDisabled
# Set ELC
Set-Mailbox mailboxName@contoso.com -ElcProcessingDisabled $true


# Clean out mailbox by searching for a phrase with a wildcard
$mbx = Get-EXOMailbox mailboxName@contoso.com;
Do {
$result = Search-Mailbox -Identity $mbx.Identity -SearchQuery 'subject:"Phrase with wildcard*"' -DeleteContent -force -WarningAction Silentlycontinue;
$result | Out-file c:\temp\mailsearch.log -append;
write-Host "Search result for username: " + $result.resultitemscount -ForegroundColor Green;
} Until ($result.resultitemscount -eq 0)

# Clean out mailbox by searching for items from a particular sender, AND a date
$inputbox = "mailboxName"
$mbx = Get-EXOMailbox $inputbox;
Do {
$result = Search-Mailbox -Identity $mbx.Identity -SearchQuery 'from:"someone@contoso.com" AND received:"02/20/2020"' -deletecontent -force -WarningAction Silentlycontinue;
write-Host "Search result for " $inputbox ": " + $result.resultitemscount -ForegroundColor Green;
 } Until ($result.resultitemscount -eq 0)

Mailbox Cleanup Commands and References

Get-EXOMailboxStatistics, Get-EXOMailboxFolderStatistics, Search-Mailbox, Get-EXOMailbox, Set-Mailbox