Skip to main content

outlook mail searchfolder add

Creates a new mail search folder in the user's mailbox

Usage

m365 outlook mail searchfolder add [options]

Options

-i, --userId [userId]

The id of the user in whose mailbox the search folder should be created. Specify either userId or userName, but not both.

-n, --userName [userName]

The UPN of the user in whose mailbox the search folder should be created. Specify either userId or userName, but not both.

--folderName <folderName>

The name of the mail search folder.

--sourceFolderIds <sourceFolderIds>

Comma-separated list of mail folders that should be searched.

--includeNestedFolders

The nested mail folders will be searched if specified.

--messageFilter <messageFilter>

The OData query to filter the messages.

-h, --help [help]

Output usage information. Optionally, specify which section of command's help you want to see. Allowed values are options, examples, remarks, permissions, response, full. Default is options.

--query [query]

JMESPath query string. See http://jmespath.org/ for more information and examples.

-o, --output [output]

Output type. json, text, csv, md, none. Default json.

--verbose

Runs command with verbose logging.

--debug

Runs command with debug logging.

Permissions

ResourcePermissions
Microsoft GraphMail.ReadWrite

Examples

Create a mail search folder in the user's mailbox specified by id for messages from the inbox that contain specific subject

m365 outlook mail searchfolder add --userId 1caf7dcd-7e83-4c3a-94f7-932a1299c844 --folderName 'CLI m365' --sourceFolderIds 'AQMkADYAAAIBDAAAAA==' --messageFilter "contains(subject, 'CLI for Microsoft 365')"

Create a mail search folder in the user's mailbox specified by UPN for incoming and outgoing messages from a specific year that contain specific text in a message body, search for messages inside all subfolders

m365 outlook mail searchfolder add --userName john.doe@contoso.com --folderName 'Power Platform Community' --sourceFolderIds 'AQMkADYAAAIBDAAAAA==,AQMkADYAAAIBDBBBBB==' --includeNestedFolders --messageFilter "contains(body/content,'Power Platform') AND receivedDateTime ge 2024-01-01 AND receivedDateTime le 2024-12-31"

Response

{
"id": "AQMkAGRlM2Y5YTkzLWI2NzAtNDczOS05YHqjbDnRgQABco84sgAAAA==",
"displayName": "Microsoft Entra",
"parentFolderId": "AQMkAGRlM2Y5YTkzLWI2NzAtNDczOS05YHqjbDnRgQAAAgEEAAAA",
"childFolderCount": 0,
"unreadItemCount": 27,
"totalItemCount": 41,
"sizeInBytes": null,
"isHidden": false,
"isSupported": true,
"includeNestedFolders": false,
"sourceFolderIds": [
"AQMkAGRlM2Y5YTkzLWI2NzAtNDczOS05YHqjbDnRgQAAAgEMAAAA"
],
"filterQuery": "contains(subject,'Microsoft Entra ID')"
}