Usage
m365 search
Description
Use the Microsoft Search to query anything
Options
| Option |
Description |
-q --queryText [queryText] |
Query to be executed in KQL format |
-s, --scopes <scopes> |
Set to specify the scope of the search request. Possible options to use: chatMessage, message, event, drive, driveItem, list, listItem, site, Bookmarks, Acronyms. Allows to pass multiple options separated by comma ',' |
--startIndex [startIndex] |
Set the number that indicates the 0-based starting point to list search results on the page. The default value is 0. |
--pageSize [pageSize] |
Set the number that indicates the number of results to be returned for a page. The default is 25 results. The maximum is 1000 results. |
--allResults |
Set to get all search results from all pages |
--resultsOnly |
Set to get only the results form the query response |
--enableTopResults |
Use to get the first three messages in the response are sorted by relevance. Use this option only when scopes is set to message type |
--select [select] |
Comma-separated list of properties to return in the search results |
--sortBy [sortBy] |
Specify the properties to sort search results and the order in a comma separated list |
--enableSpellingSuggestion |
Set to get the suggested spelling correction information for typos in the user query |
--enableSpellingModification |
Set to get the search results for the corrected query when there are no results for the original query with typos, and get the corresponding correction information |
Examples
Queries messages in the current user mailbox that contain the string "contoso" in any part of the message (the sender name, subject, message body, or any attachments). The query returns the first 100 results. The search results are ordered by createdDateTime descending and id descending and date ascending
m365 search --scopes 'message' --queryText 'contoso' --size 100 --sortBy 'createdDateTime:desc,id:desc,date'
Queries list items and sites that contain the string "accountt" and requests a spelling modification for the query.
m365 search --scopes 'listItem, site' --queryText 'accountt' --enableSpellingSuggestion --enableSpellingModification
possible result of the above command
{
"value": [
{
"searchTerms": [
"account"
],
"hitsContainers": [
{
"total": 1,
"moreResultsAvailable": false,
"hits": [
{
"hitId": "FlULeN/ui/1GjLx1rUfio5UAAEl",
"rank": 1,
"summary": "",
"resource": {
"@odata.type": "#microsoft.graph.listItem",
"createdDateTime": "2019-06-10T06:37:43Z",
"lastModifiedDateTime": "2019-06-10T06:37:43Z",
"name": "web_part_test_long Notebook",
"webUrl": "https://contoso.sharepoint.com/sites/contoso-team/Lists/Issue tracker list/DispForm.aspx?ID=1",
"sharepointIds": {
"listId": "33498de0-d695-4d23-ac26-e1bf95a3206e",
"listItemId": "13"
},
"createdBy": {
"user": {
"displayName": "System Account"
}
},
"lastModifiedBy": {
"user": {
"displayName": "System Account"
}
},
"parentReference": {
"sharepointIds": {
"listId": "da61a2b0-4120-4a3f-812b-0fc0d79bf16b"
},
"siteId": "m365x231305.sharepoint.com,5724d91f-650c-4810-83cc-61a8818917d6,c3ba25dc-2c9f-48cb-83be-74cdf68ea5a0"
}
}
}
]
}
],
"queryAlterationResponse": {
"@odata.type": "#microsoft.substrateSearch.alterationResponse",
"originalQueryString": "accountt",
"queryAlteration": {
"@odata.type": "#microsoft.substrateSearch.searchAlteration",
"alteredQueryString": "account",
"alteredHighlightedQueryString": "account",
"alteredQueryTokens": [
{
"offset": 0,
"length": 8,
"suggestion": "account"
}
]
},
"queryAlterationType": "Modification"
}
}
]
}
Default properties
Additional Info
based on MS Graph Microsoft Search API to query data
https://graph.microsoft.com/v1.0/search/query
checking the MS Graph explorer gives a feeling how much may be achieved with this 🤩
Some other comments:
{
"field": "FileType",
"size": 20,
"bucketDefinition": {
"sortBy": "count",
"isDescending": "true",
"minimumCount": 0
}
}
Usage
m365 search
Description
Use the Microsoft Search to query anything
Options
-q --queryText [queryText]-s, --scopes <scopes>chatMessage,message,event,drive,driveItem,list,listItem,site,Bookmarks,Acronyms. Allows to pass multiple options separated by comma ','--startIndex [startIndex]--pageSize [pageSize]--allResults--resultsOnly--enableTopResultsscopesis set tomessagetype--select [select]--sortBy [sortBy]--enableSpellingSuggestion--enableSpellingModificationExamples
Queries messages in the current user mailbox that contain the string "contoso" in any part of the message (the sender name, subject, message body, or any attachments). The query returns the first 100 results. The search results are ordered by createdDateTime descending and id descending and date ascending
Queries list items and sites that contain the string "accountt" and requests a spelling modification for the query.
possible result of the above command
Default properties
Additional Info
based on MS Graph Microsoft Search API to query data
https://graph.microsoft.com/v1.0/search/querychecking the MS Graph explorer gives a feeling how much may be achieved with this 🤩
Some other comments:
scopeoption - not sure of the name here 🤔 maybeentityTypewould be better and more aligned with the API responsequeryStringsupports KQLisDescendingproperty for each field 🤔https://learn.microsoft.com/en-us/graph/api/resources/search-api-overview?view=graph-rest-1.0#sort-search-results. I wonder what would be the best/easiest way to allow the same in this command. Any suggestions?aggregationand we would accept JSON like