PowerShell Microsoft 365
Cmdlets of the current modules (Exchange Online, Microsoft Graph PowerShell, Teams, SharePoint Online). MSOnline and AzureAD are deprecated: use Microsoft Graph PowerShell.
Getting started
Connecting
Install the modules first (once) with Install-Module -Scope CurrentUser, then connect at each session.
Connect-ExchangeOnline -UserPrincipalName admin@contoso.comExchange Online (ExchangeOnlineManagement module). Add -ShowBanner:$false for shorter output. Disconnect: Disconnect-ExchangeOnline -Confirm:$false.
Connect-MgGraph -Scopes 'User.Read.All','Group.ReadWrite.All','Directory.Read.All'Microsoft Graph PowerShell: request only the scopes you need (least privilege). Check with Get-MgContext. Common scopes: User.ReadWrite.All, Group.ReadWrite.All, Directory.ReadWrite.All, Policy.Read.All, DeviceManagementManagedDevices.Read.All, AuditLog.Read.All.
Connect-MicrosoftTeamsTeams (MicrosoftTeams module). Teams Administrator role or higher.
Connect-SPOService -Url https://contoso-admin.sharepoint.comSharePoint Online (Microsoft.Online.SharePoint.PowerShell module), admin center URL. Alternative: PnP.PowerShell.
Connect-IPPSSession -UserPrincipalName admin@contoso.comSecurity & Compliance (Defender, Purview): same module as Exchange Online.
Results
MSOnline and AzureAD (Msol* and *-AzureAD* cmdlets) are deprecated and no longer receive fixes: migrate to Microsoft Graph PowerShell (Mg*). Test with -WhatIf first when it exists.
Full list
Show all 51 entries
Get-MailboxGet-Mailbox [-Identity <id>] [-ResultSize Unlimited]Lists mailboxes or shows a mailbox's properties.
Get-Mailbox -Identity user@contoso.com | Format-List DisplayName,PrimarySmtpAddress,ArchiveStatus,LitigationHoldEnabled Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails SharedMailboxSet-MailboxSet-Mailbox -Identity <id> [properties]Changes a mailbox (quota, address, forwarding, archive, retention).
Set-Mailbox -Identity user@contoso.com -ForwardingSmtpAddress ext@example.com -DeliverToMailboxAndForward $true Set-Mailbox -Identity user@contoso.com -LitigationHoldEnabled $trueSet-MailboxAutoReplyConfigurationSet-MailboxAutoReplyConfiguration -Identity <id> -AutoReplyState Enabled|Disabled|ScheduledEnables, schedules or turns off a mailbox's out-of-office automatic reply (internal and external message).
Set-MailboxAutoReplyConfiguration -Identity user@contoso.com -AutoReplyState Enabled -InternalMessage 'Absent jusqu''au 5 janvier.' -ExternalMessage 'Absent jusqu''au 5 janvier.' Set-MailboxAutoReplyConfiguration -Identity user@contoso.com -AutoReplyState Scheduled -StartTime '2026-12-22 18:00' -EndTime '2027-01-05 08:00' -InternalMessage 'Congés' Set-MailboxAutoReplyConfiguration -Identity user@contoso.com -AutoReplyState DisabledNew-MailboxNew-Mailbox -Shared -Name <name> -DisplayName <name>Creates a shared mailbox (or room/equipment with -Room, -Equipment).
New-Mailbox -Shared -Name 'Support' -DisplayName 'Support' -PrimarySmtpAddress support@contoso.comAdd-MailboxPermissionAdd-MailboxPermission -Identity <mailbox> -User <user> -AccessRights FullAccessGives full access to a mailbox (read/write delegation).
Add-MailboxPermission -Identity shared@contoso.com -User user@contoso.com -AccessRights FullAccess -AutoMapping $trueAdd-RecipientPermissionAdd-RecipientPermission -Identity <mailbox> -Trustee <user> -AccessRights SendAsAllows 'Send as' on a mailbox or group.
Add-RecipientPermission -Identity shared@contoso.com -Trustee user@contoso.com -AccessRights SendAs -Confirm:$falseGet-MailboxStatisticsGet-MailboxStatistics -Identity <id>A mailbox's size, item count and last logon.
Get-MailboxStatistics user@contoso.com | Select DisplayName,TotalItemSize,ItemCount,LastLogonTimeGet-MessageTraceV2Get-MessageTraceV2 -SenderAddress <sender> -StartDate <date> -EndDate <date>Traces a message (delivered, delayed, rejected) over the last 10 days. Replaces Get-MessageTrace.
Get-MessageTraceV2 -RecipientAddress user@contoso.com -StartDate (Get-Date).AddDays(-2) -EndDate (Get-Date)Start-HistoricalSearchStart-HistoricalSearch -ReportTitle <title> -ReportType MessageTrace ...Starts a message trace search beyond 10 days (up to 90 days), delivered by email.
Start-HistoricalSearch -ReportTitle 'Trace' -ReportType MessageTrace -StartDate (Get-Date).AddDays(-30) -EndDate (Get-Date) -SenderAddress a@example.com -NotifyAddress admin@contoso.comNew-TransportRuleNew-TransportRule -Name <name> -Conditions... -Actions...Creates a mail flow rule (disclaimer, block, redirect).
New-TransportRule -Name 'Étiquette externe' -FromScope NotInOrganization -PrependSubject '[EXTERNE] 'Get-DistributionGroupMemberGet-DistributionGroupMember -Identity <group>Lists the members of a distribution list.
Get-DistributionGroupMember -Identity team@contoso.com -ResultSize Unlimited | Select DisplayName,PrimarySmtpAddressAdd-DistributionGroupMemberAdd-DistributionGroupMember -Identity <group> -Member <user>Adds a member to a distribution list.
Add-DistributionGroupMember -Identity team@contoso.com -Member user@contoso.comSet-CalendarProcessingSet-CalendarProcessing -Identity <room> -AutomateProcessing AutoAcceptSets automatic meeting acceptance for a room or equipment.
Set-CalendarProcessing -Identity salle1@contoso.com -AutomateProcessing AutoAccept -AllowConflicts $falseAdd-MailboxFolderPermissionAdd-MailboxFolderPermission -Identity <mailbox>:\Calendar -User <user> -AccessRights ReviewerShares a folder (calendar, inbox) with a user.
Add-MailboxFolderPermission -Identity user@contoso.com:\Calendar -User collegue@contoso.com -AccessRights EditorGet-EXOMailboxGet-EXOMailbox -Identity <id> -Properties <list>Fast, lightweight version of Get-Mailbox for large volumes.
Get-EXOMailbox -ResultSize Unlimited -Properties ProhibitSendQuota | Select DisplayName,ProhibitSendQuotaEnable-Mailbox (archive)Enable-Mailbox -Identity <id> -ArchiveEnables a mailbox's online archive.
Enable-Mailbox -Identity user@contoso.com -ArchiveConnect-MgGraphConnect-MgGraph -Scopes <scopes> [-TenantId <id>] [-NoWelcome]Opens a Microsoft Graph PowerShell session with the requested scopes.
Connect-MgGraph -Scopes 'User.ReadWrite.All' -NoWelcome Get-MgContext | Select Account,TenantId,ScopesGet-MgUserGet-MgUser [-UserId <id>] [-Filter <odata>] [-Property <list>] [-All]Reads a user or lists Entra ID accounts. Replaces Get-MsolUser / Get-AzureADUser.
Get-MgUser -UserId user@contoso.com -Property DisplayName,AccountEnabled,SignInActivity Get-MgUser -All -Filter "accountEnabled eq false" | Select DisplayName,UserPrincipalNameNew-MgUserNew-MgUser -DisplayName <name> -UserPrincipalName <upn> -MailNickname <alias> -AccountEnabled -PasswordProfile <hash>Creates an Entra ID user.
New-MgUser -DisplayName 'Jean Dupont' -UserPrincipalName jean@contoso.com -MailNickname jean -AccountEnabled -PasswordProfile @{ Password = '<mot de passe>'; ForceChangePasswordNextSignIn = $true }Update-MgUserUpdate-MgUser -UserId <id> [-property value]Changes a user (department, title, enablement, usage location).
Update-MgUser -UserId user@contoso.com -AccountEnabled:$false Update-MgUser -UserId user@contoso.com -UsageLocation FRRevoke-MgUserSignInSessionRevoke-MgUserSignInSession -UserId <id>Revokes a user's refresh tokens and sessions (compromised account).
Revoke-MgUserSignInSession -UserId user@contoso.comSet-MgUserLicenseSet-MgUserLicense -UserId <id> -AddLicenses @{SkuId=...} -RemoveLicenses @()Assigns or removes Microsoft 365 licences.
Get-MgSubscribedSku | Select SkuPartNumber,SkuId,ConsumedUnits Set-MgUserLicense -UserId user@contoso.com -AddLicenses @{SkuId='<SkuId>'} -RemoveLicenses @()Get-MgGroupGet-MgGroup [-GroupId <id>] [-Filter <odata>] [-All]Lists Entra ID groups (Microsoft 365, security).
Get-MgGroup -All -Filter "startsWith(displayName,'Ventes')"New-MgGroupMemberNew-MgGroupMember -GroupId <id> -DirectoryObjectId <id>Adds a member to an Entra ID group.
New-MgGroupMember -GroupId $groupId -DirectoryObjectId (Get-MgUser -UserId user@contoso.com).IdGet-MgUserAuthenticationMethodGet-MgUserAuthenticationMethod -UserId <id>Lists a user's authentication methods (MFA).
Get-MgUserAuthenticationMethod -UserId user@contoso.com | Select Id,AdditionalPropertiesGet-MgAuditLogSignInGet-MgAuditLogSignIn -Filter <odata> -Top <n>Entra ID sign-in log (failures, location, conditional access).
Get-MgAuditLogSignIn -Filter "userPrincipalName eq 'user@contoso.com'" -Top 20 | Select CreatedDateTime,AppDisplayName,IPAddress,StatusGet-MgDirectoryRoleGet-MgDirectoryRole / Get-MgDirectoryRoleMemberLists the activated administrator roles and their members.
$r = Get-MgDirectoryRole -Filter "displayName eq 'Global Administrator'"; Get-MgDirectoryRoleMember -DirectoryRoleId $r.IdGet-MgSubscribedSkuGet-MgSubscribedSkuThe tenant's purchased, consumed and available licences.
Get-MgSubscribedSku | Select SkuPartNumber,ConsumedUnits,@{n='Total';e={$_.PrepaidUnits.Enabled}}Get-MgIdentityConditionalAccessPolicyGet-MgIdentityConditionalAccessPolicyLists conditional access policies.
Get-MgIdentityConditionalAccessPolicy | Select DisplayName,StateGet-TeamGet-Team [-DisplayName <name>] [-User <upn>]Lists Teams teams.
Get-Team -DisplayName 'Projet' | Select GroupId,DisplayName,Visibility,ArchivedNew-TeamNew-Team -DisplayName <name> -Visibility PrivateCreates a team (and its Microsoft 365 group).
New-Team -DisplayName 'Projet Alpha' -Visibility Private -Owner admin@contoso.comAdd-TeamUserAdd-TeamUser -GroupId <id> -User <upn> -Role MemberAdds a member or owner to a team.
Add-TeamUser -GroupId $groupId -User user@contoso.com -Role MemberGet-CsOnlineUserGet-CsOnlineUser -Identity <upn>Shows a user's Teams configuration (telephony, policies).
Get-CsOnlineUser -Identity user@contoso.com | Select DisplayName,TeamsMeetingPolicy,LineUri,InterpretedUserTypeGrant-CsTeamsMeetingPolicyGrant-CsTeamsMeetingPolicy -Identity <upn> -PolicyName <policy>Assigns a Teams meeting policy to a user.
Grant-CsTeamsMeetingPolicy -Identity user@contoso.com -PolicyName 'RestrictedAnonymous'Get-SPOSiteGet-SPOSite [-Identity <url>] [-Limit All]Lists SharePoint site collections.
Get-SPOSite -Limit All | Select Url,StorageUsageCurrent,SharingCapabilitySet-SPOSiteSet-SPOSite -Identity <url> [-SharingCapability ...] [-StorageQuota ...]Changes a site (external sharing, quota, lock).
Set-SPOSite -Identity https://contoso.sharepoint.com/sites/rh -SharingCapability Disabled Set-SPOSite -Identity https://contoso.sharepoint.com/sites/rh -LockState ReadOnlyGet-SPOTenantGet-SPOTenantGlobal SharePoint and OneDrive tenant settings (sharing, sync).
Get-SPOTenant | Select SharingCapability,DefaultSharingLinkType,OneDriveStorageQuotaGet-SPOUser / Add-SPOUserGet-SPOUser -Site <url> / Add-SPOUser -Site <url> -LoginName <upn> -Group <group>Views or adds users in a site.
Get-SPOUser -Site https://contoso.sharepoint.com/sites/rh -Limit All Add-SPOUser -Site https://contoso.sharepoint.com/sites/rh -LoginName user@contoso.com -Group 'RH Members'Restore-SPODeletedSiteRestore-SPODeletedSite -Identity <url>Restores a deleted site (tenant recycle bin, 93 days).
Get-SPODeletedSite | Select Url,DeletionTime Restore-SPODeletedSite -Identity https://contoso.sharepoint.com/sites/rhGet-MgDeviceManagementManagedDeviceGet-MgDeviceManagementManagedDevice [-Filter <odata>] [-All]Lists devices managed by Intune (compliance, OS, last contact).
Get-MgDeviceManagementManagedDevice -All -Filter "operatingSystem eq 'Windows'" | Select DeviceName,UserPrincipalName,ComplianceState,LastSyncDateTimeSync-MgDeviceManagementManagedDeviceSync-MgDeviceManagementManagedDevice -ManagedDeviceId <id>Requests an immediate sync of an Intune device.
Sync-MgDeviceManagementManagedDevice -ManagedDeviceId $idInvoke-MgRetireDeviceManagementManagedDeviceInvoke-MgRetireDeviceManagementManagedDevice -ManagedDeviceId <id>Retires a device from management (removes company data, keeps personal data).
Invoke-MgRetireDeviceManagementManagedDevice -ManagedDeviceId $idGet-QuarantineMessageGet-QuarantineMessage -StartReceivedDate <date> -EndReceivedDate <date>Lists messages in Defender for Office 365 quarantine.
Get-QuarantineMessage -RecipientAddress user@contoso.com -StartReceivedDate (Get-Date).AddDays(-7) -EndReceivedDate (Get-Date) | Select ReceivedTime,SenderAddress,Subject,TypeGet-MalwareFilterPolicyGet-MalwareFilterPolicy / Set-MalwareFilterPolicyViews or sets the anti-malware policy.
Get-MalwareFilterPolicy | Select Name,EnableFileFilter,FileTypesGet-SafeLinksPolicyGet-SafeLinksPolicyDefender for Office 365 Safe Links policies.
Get-SafeLinksPolicy | Select Name,EnableSafeLinksForEmail,ScanUrls,DoNotRewriteUrlsSearch-UnifiedAuditLogSearch-UnifiedAuditLog -StartDate <date> -EndDate <date> -UserIds <upn> -Operations <list>Queries the unified audit log (sign-ins, file access, mailbox rules).
Search-UnifiedAuditLog -StartDate (Get-Date).AddDays(-7) -EndDate (Get-Date) -UserIds user@contoso.com -Operations New-InboxRule,Set-InboxRule -ResultSize 500New-ComplianceSearchNew-ComplianceSearch -Name <name> -ExchangeLocation All -ContentMatchQuery <KQL>Creates a Purview eDiscovery content search (then Start-ComplianceSearch).
New-ComplianceSearch -Name 'Facture-X' -ExchangeLocation All -ContentMatchQuery 'subject:"Facture X"' Start-ComplianceSearch -Identity 'Facture-X'Get-DlpCompliancePolicyGet-DlpCompliancePolicyLists data loss prevention (DLP) policies.
Get-DlpCompliancePolicy | Select Name,Mode,EnabledConnect-MsolServiceConnect-MsolServiceSign-in for the MSOnline module, deprecated. Replace with Connect-MgGraph.
# Ancien : Connect-MsolService ; Get-MsolUser -UserPrincipalName user@contoso.com # Nouveau : Connect-MgGraph -Scopes 'User.Read.All' ; Get-MgUser -UserId user@contoso.comConnect-AzureADConnect-AzureADSign-in for the AzureAD module, deprecated. Replace with Connect-MgGraph.
# Ancien : Get-AzureADGroupMember -ObjectId $id # Nouveau : Get-MgGroupMember -GroupId $idSet-MsolUserPasswordSet-MsolUserPassword -UserPrincipalName <upn> -NewPassword <password>Resets a password (MSOnline, deprecated). Graph equivalent: Update-MgUser with -PasswordProfile.
Update-MgUser -UserId user@contoso.com -PasswordProfile @{ Password = '<mot de passe>'; ForceChangePasswordNextSignIn = $true }