Skip to content
Download

CLI Reference

FlagDescription
-h, --helpShow help for any command

Search a pre-processed index of the Microsoft Graph OpenAPI specification to find available endpoints, required scopes, and API details.

Terminal window
msgraph openapi-search [flags]

At least one of --query, --resource, or --method is required.

Flags:

FlagTypeDescriptionDefault
--querystringFree-text search (searches path, summary, description)
--resourcestringFilter by resource name (e.g. users, groups, messages)
--methodstringFilter by HTTP method (GET, POST, PUT, PATCH)
--limitintMax results20

Examples:

Terminal window
msgraph openapi-search --query "list users"
msgraph openapi-search --resource users --method GET
msgraph openapi-search --query "send mail" --method POST

Output: JSON with count and results array.


Search a pre-processed index of Microsoft Graph API documentation to find per-endpoint permissions, supported query parameters, default properties, required headers, and endpoint-specific gotchas.

Terminal window
msgraph api-docs-search [flags]

Use --endpoint to look up endpoint details (permissions, query params, headers). Use --resource to look up resource properties (filter operators, default status).

Flags:

FlagTypeDescriptionDefault
--endpointstringSearch by endpoint path (e.g. /users, /me/messages)
--resourcestringSearch by resource type name (e.g. user, group, message)
--methodstringFilter by HTTP method (GET, POST, PUT, PATCH)
--querystringFree-text search across all fields
--limitintMax results10

Examples:

Terminal window
msgraph api-docs-search --endpoint /users --method GET
msgraph api-docs-search --endpoint /me/messages
msgraph api-docs-search --resource user
msgraph api-docs-search --resource group --query "filter"
msgraph api-docs-search --query "ConsistencyLevel"

Output: JSON with matching endpoint documentation including permissions, query parameter support, headers, and property details.


Search a curated library of community-contributed Microsoft Graph API query samples to find the right API call for a given task. These samples map natural-language intents (e.g. “list all Conditional Access policies”) to exact Graph API queries, including multi-step workflows.

Terminal window
msgraph sample-search [flags]

Flags:

FlagTypeDescriptionDefault
--querystringFree-text search (searches intent and query fields)
--productstringFilter by product (entra, intune, exchange, teams, sharepoint, security, general)
--limitintMax results10

Examples:

Terminal window
msgraph sample-search --query "conditional access policies"
msgraph sample-search --query "send email"
msgraph sample-search --product entra
msgraph sample-search --query "managed devices" --product intune

Output: JSON with matching samples including intent, Graph API queries, and product category.


Execute an HTTP request against the Microsoft Graph API. The URL can be a full URL or a relative path starting with /.

By default, only GET requests are allowed. Use --allow-writes to enable POST, PUT, and PATCH requests. DELETE is always blocked for safety.

Terminal window
msgraph graph-call <METHOD> <URL> [flags]

Args:

ArgDescription
METHODHTTP method: GET, POST, PUT, PATCH
URLFull URL or relative path (e.g. /me, /users, /me/messages)

Flags:

FlagTypeDescriptionDefault
--allow-writesboolAllow POST, PUT, PATCH requests (agent must confirm with user)false
--bodystringJSON request body
--headersstringsCustom headers (key:value)
--api-versionstringv1.0 or betabeta
--selectstringOData $select
--filterstringOData $filter
--topintOData $top
--expandstringOData $expand
--orderbystringOData $orderby
--scopesstringsAdditional permission scopes to request
--outputstringjson or rawjson

Examples:

Terminal window
msgraph graph-call GET /me
msgraph graph-call GET /me/messages --select "subject,from" --top 10
msgraph graph-call POST /me/messages --body '{"subject":"Hello"}' --allow-writes

Output: JSON with statusCode and body.


Authenticate to a Microsoft 365 tenant. For delegated auth, uses interactive browser or device code flow. For app-only auth (client secret, certificate, managed identity, workload identity), verifies that credentials are valid.

Terminal window
msgraph auth signin [flags]

Flags:

FlagTypeDescription
--device-codeboolUse device code flow instead of browser (delegated only)
--scopesstringsPermission scopes to request (default: User.Read, delegated only)

App-only behavior: When app-only auth is detected (via environment variables), auth signin acquires a token to verify credentials and shows the auth status. The --device-code and --scopes flags are ignored.

Output: JSON with sign-in status.


Clear the current authentication session and token cache.

Terminal window
msgraph auth signout

Output: JSON confirmation.


Display the current sign-in state, including the signed-in user/app and tenant.

Terminal window
msgraph auth status

Output:

{
"signedIn": true,
"username": "user@contoso.com",
"tenantId": "common",
"clientId": "14d82eec-204b-4c2f-b7e8-296a70dab67e",
"authMethod": "delegated",
"environment": "login.microsoftonline.com"
}

For app-only auth, authMethod shows the detected method (e.g. client-secret, certificate, managed-identity, workload-identity) and username reflects the auth type.


Sign out of the current tenant and sign in to a new one.

Terminal window
msgraph auth switch-tenant [tenant-id] [flags]

Args:

ArgDescription
tenant-idThe Entra ID tenant ID to switch to

Flags: Same as auth signin.


Generate shell autocompletion scripts for msgraph.

Terminal window
msgraph completion <shell>

Supported shells: bash, fish, powershell, zsh.

See msgraph completion <shell> --help for instructions on how to install the generated script.