Managing mail folders is a common task for Microsoft 365 administrators. Whether you’re auditing user mailboxes, retrieving folder structure, or building automation around mailbox cleanup, the Get-MgUserMailFolder cmdlet comes in handy.
In this guide, we’ll walk through what this cmdlet does, why it’s useful, how to use it effectively, and provide real-world examples to help you get started.
Get-MgUserMailFolder is a Microsoft Graph PowerShell cmdlet used to retrieve the mail folders of a user in Microsoft 365. You can fetch all folders, a specific folder, child folders, or even apply filters to fetch folders based on properties like display name or folder ID.
This cmdlet is part of the Microsoft.Graph.Users.Mail module and requires proper permissions to access a user's mailbox.
Here are some reasons administrators and developers rely on Get-MgUserMailFolder:
Get-MgUserMailFolder -UserId <String> [-MailFolderId <String>] [-Property <String[]>] [-Filter <String>]
Parameters:
Get-MgUserMailFolder -UserId "user@domain.com"
This command retrieves all mail folders from the user's mailbox, including default and custom folders.
Get-MgUserMailFolder -UserId "user@domain.com" -MailFolderId "AQMkAGI2TAAA="
If you already have the folder ID (for example, from a previous query), you can retrieve the full folder details using this method.
Get-MgUserMailFolder -UserId "user@domain.com" -Property @("Id", "DisplayName", "ChildFolderCount")
Limit the output to only show selected properties — this makes your scripts cleaner and faster when processing large mailboxes.
Get-MgUserMailFolder -UserId "user@domain.com" -Filter "displayName eq 'Inbox'"
Want to find only the "Inbox"? Use the -Filter parameter to zero in on specific folders by name.
You’ll need Mail.Read or Mail.ReadWrite delegated permissions, or Mail.ReadBasic.All application permissions when using app-only access.
Yes. Each folder object contains a ChildFolderCount and ChildFolders relationship, which you can explore using the -ExpandProperty parameter.
You may consider paginating the results or using Select-Object to limit the returned fields for performance.
Get-MgUserMailFolder is a versatile tool for managing Microsoft 365 mailboxes. Whether you're performing audits, building automation workflows, or simply exploring user folder structures, this cmdlet makes it easy.
By mastering the examples above, you’ll be ready to use Get-MgUserMailFolder in real-world scenarios — with clarity, control, and confidence.
Did You Know? Managing Microsoft 365 applications is even easier with automation. Try our Graph PowerShell scripts to automate tasks like generating reports, cleaning up inactive Teams, or assigning licenses efficiently.
Ready to get the most out of Microsoft 365 tools? Explore our free Microsoft 365 administration tools to simplify your administrative tasks and boost productivity.
© Your Site Name. All Rights Reserved. Design by HTML Codex