Simplify Microsoft Graph interactions with the intuitive Microsoft Graph CLI now in preview. Microsoft Graph CLI is a command-line tool, generated by Kiota, that provides convenient methods to access Microsoft Graph API capabilities on any operating system and any shell.
The CLI can be used in a variety of scenarios, from quick one-off tasks to complex automation scripts. It supports a wide range of features, including authentication, data retrieval, and data manipulation. Check out what more you can do.
Cross platform support for the Microsoft Graph CLI
The CLI tool should work on any terminal. We recommend:
- Windows Terminal + version
- MacOS (Minimum version: 10.12 Sierra) terminal
- PowerShell version 7.3.2
Installation
Download the CLI to get started for Windows, Mac, Linux or Docker on the assets link of the latest release: CLI Download. Find platform specific nuances on the CLI Read Me.
Optional:
Follow the instructions in Register an application for Microsoft identity platform authentication to get an application ID (also known as a client ID).
Replace YOUR_CLIENT_ID with the client ID from your app registration.
Multiple authentication options for the Microsoft Graph CLI
The CLI supports multiple authentication options to suit different scenarios for both Delegated and App only experiences.
To view supported authentication options, run the following command
mgc login –help
Delegated authentication options
- Interactive Browser Authentication:
Use this method if you want to authenticate interactively by entering your Microsoft 365 credentials in a web browser.
mgc login –-strategy InteractiveBrowser
- Device Code Authentication (default auth option)
Use this method if you’re unable to authenticate directly through a web browser and need to authenticate on a separate device.
mgc login –strategy DeviceCode
App-only authentication options
- Client Certificate authentication
mgc login --strategy ClientCertificate
- Environment login
Supports both certificate files and client secret using environment variables and is used by client application that needs to authenticate itself using a client ID.
mgc login --strategy Environment
Supported environment variables are:
- AZURE_TENANT_ID
- AZURE_CLIENT_ID
- AZURE_CLIENT_SECRET
- AZURE_CLIENT_CERTIFICATE_PATH
- AZURE_CLIENT_CERTIFICATE_PASSWORD
- AZURE_CLIENT_SEND_CERTIFICATE_CHAIN
Support for multiple output formats
Several output formats are supported using the –output option which can display data as JSON (default), table or text.
You can turn off Indent JSON responses using the –json-no-indent argument for the JSON output formatter.
Usage
Once installed, you can start using the Microsoft Graph CLI to interact with the Microsoft Graph API. Here are some examples of common commands:
- To check permissions for scopes Add -h to your command to view information that contains documentation links with permissions.
- To check logged in user
You can access the logged in user’s details using:
mgc me get
- To get information about a specific user, use the `user` command with the user’s ID or email address:
mgc user get --id <user_id>
- To create a new group, use the `group` command with the desired group name:
mgc group create --name <group_name>
- To upload a file to OneDrive, use the `drive item` command with the file path and destination drive:
mgc drive item upload --path <file_path> --drive <drive_id>
For a complete list of available commands and options, refer to the CLI documentation. You can also add –debug to your command to get more details on your interactions.
Samples
You can find additional samples here (contain sample commands for CMD, PowerShell & Bash)Â CLI samples
Feedback and bug reports
We welcome your feedback and bug reports for this release candidate version. If you encounter any issues or have suggestions for improvement, please open an issue on the GitHub repository.
Changelog
v1.0.0-preview1 (Public Preview)
Additional capabilities supported in this release include:
- support for JMESPath queries via the –query option
mgc users list --query "value[].{Name: displayName, Email: mail}"
- Header command options can now be called multiple times. The header values will now be additive.
- Contains documentation links to API reference.
- Add automatic page iteration via the –all command option.
Roadmap
The final stable release of the Microsoft Graph CLI will be available by September 2023. We are incorporating feedback and addressing reported issues to provide a reliable and efficient tool for developers. Stay tuned for further updates!
Follow us on Twitter @Microsoft365Dev to stay up to date on news and announcements. Thank you for trying out the Microsoft Graph CLI release candidate.
Happy coding!
0 comments