CLI for Microsoft 365 v7
We’ve just published a new major version of the CLI for Microsoft 365 with new commands for working with and managing Microsoft 365 and SharePoint Framework projects on any platform.
CLI for Microsoft 365 is a cross-platform command line tool based on Node.js that helps you manage many things around Microsoft 365 and your SPFx project. You may manage OneDrive, Planner, Power Apps and Automate, Teams, Viva Engage (Yammer), SharePoint (of course), and many many more. The list keeps on growing and growing.
As we keep adding new commands to CLI for Microsoft 365, we noticed several areas that we should improve, to make using the CLI more intuitive and consistent. While our major releases are evolutionary in nature, we’ve also added some new commands and improvements to the CLI.
To help you upgrade to v7, we prepared a summary of breaking changes and the recommended actions. For more information see the v7 Upgrade Guidance in our docs.
Following is an overview of the most noteworthy changes in v7.
For the complete list of what’s new and changed, see the release notes.
Once a year we take the opportunity to look at all of the functionality that we have in the CLI, and see how we can make it more consistent and intuitive. Typically, this leads to breaking changes. We’ve done our best to minimize the impact of these changes, but we still recommend that you review the v7 Upgrade Guidance in our docs to verify if you’re affected by any of these changes before you upgrade to v7.
One example of this is the following. When doing destructive things like deleting a site, CLI for Microsoft 365 asks you to confirm your intention. In version 7 of the CLI for Microsoft 365, we have renamed the option
--force in all commands. This change aims to be more consistent with other CLI tools where
--force is used to suppress prompts.
SharePoint Framework (SPFx) allows you to build solutions for Microsoft Teams, Microsoft Viva, Outlook, the Microsoft 365 app and SharePoint. v1.18.0 of SPFx introduced several new features including designing Viva Connections custom cards for your dashboard. Aside from that, developers may now use Node.JS 18 to work with SPFx.
To benefit from these, and other improvements introduced in SPFx v1.18.0, upgrade your existing projects using the CLI for Microsoft 365.
Important: CLI for Microsoft 365 won’t upgrade your project. Instead, it will provide you with a report that you can use to upgrade your project yourself.
To upgrade your SPFx projects to v1.18.0, run the following command:
m365 spfx project upgrade --toVersion 1.18.0 --output md > report.md
You can also request a more interactive report built on top of the VSCode CodeTour extension, by running:
m365 spfx project upgrade --toVersion 1.18.0 --output tour
We’ve also updated other SPFx-related commands to support SPFx v1.18.0.
In our search for an even better user experience, we’ve had a good look at interactivity in the CLI for Microsoft 365. We’ve done a lot of work on it, and we’re proud to finally present the results of those efforts! In the new version, the CLI for Microsoft 365 will (by default) prompt the user to select or enter extra information that’s necessary for the command to run. This includes prompts for required options that the user forgot and requests to select an item from a result set, for example, if the CLI for Microsoft 365 found multiple items with the same name.
Toggling this behavior on or off can be done as follows:
m365 cli config set --key prompt --value true
The following example shows how the CLI for Microsoft 365 prompts the user to select and fill in a required property and select one of the found applications:
To learn more about configuring the CLI for Microsoft 365, also take a look at our m365 setup command, which makes it easy to configure the CLI to work best in your specific scenario.
Lists are one of the most powerful features of SharePoint, providing a flexible and customizable way to store and manage data. Whether you need to track tasks, manage contacts, or store documents, lists can help you do it all. A part of working with lists is the ability to add attachments to list items, making it easy to keep all relevant information in one place. In this release, we bring support for managing list attachments using the CLI for Microsoft 365.
To add a new attachment to a list item from a local file, run:
m365 spo listitem attachment add --webUrl https://contoso.sharepoint.com/sites/project-x --listTitle "DemoList" --listItemId 147 --filePath "C:/Reports/File1.jpg"
To get information about a list item attachment, run:
m365 spo listitem attachment get --webUrl https://contoso.sharepoint.com/sites/project-x --listTitle "Demo List" --listItemId 147 --fileName "File1.jpg"
To update an attachment, run:
m365 spo listitem attachment set --webUrl https://contoso.sharepoint.com/sites/project-x --listTitle "Demo List" --listItemId 147 --fileName "File1.jpg" --filePath "C:/Reports/File2.jpg"
To remove an attachment from a list item, run:
m365 spo listitem attachment remove --webUrl https://contoso.sharepoint.com/sites/project-x --listTitle "Demo List" --listItemId 147 --fileName "File1.jpg"
For more information, check out the documentation for each command:
- m365 list item attachment add
- m365 list item attachment get
- m365 list item attachment set
- m365 list item attachment remove
Using the CLI for Microsoft 365 it’s already possible to remove Microsoft 365 groups. We’ve now added a new command to remove other types of Entra ID Groups.
To remove an Entra ID Group by display name, run:
m365 aad group remove --displayName Developers
To learn more, see the m365 aad group remove command documentation.
As more and more organizations embrace collaboration through Microsoft 365, guest access has become an important feature of company systems. Cross-tenant access allows users from different organizations to access and collaborate on shared resources, such as documents and lists. This can help streamline business processes and improve overall productivity. To set up cross-tenant access confidently, it’s important to get basic tenant information in a secure way. Using the new command
tenant info get it’s now super easy to search for tenant information by entering the domain name.
To get tenant information for the Contoso tenant, run:
m365 tenant info get --domainName contoso.com
To learn more, see the m365 tenant info get command documentation.
For people who are using the CLI programmatically this change is a big one, as it will require you to rewrite your own tooling to ESM as well.
Here are some things that we are currently working on.
We’re always implementing new commands. How about a command to start a meeting in Microsoft Teams? Or a new command to copy files? The Entra ID space is also extended with new functionality to list group users and new options.
Last but not least, we’re prepping new commands on working with external connections: creating external items, adding urlToItem resolvers and more is to come here. External Connections are useful when indexing content for use by Microsoft Search and Microsoft 365 Copilot. Working with external connections was already possible, but because the scope has now broadened to Copilot as well, we’re considering a rename. If you’ve got valuable input in this area, do let us know! We’d like to hear your opinion.
The CLI for Microsoft 365 is a cross-platform / cross-shell tool. This has always been an important feature. However, many of our users are familiar with and use PowerShell in their everyday life. To make the end-to-end experience for these users even better, we’re working on some interesting ideas to allow the CLI for Microsoft 365 to work even better when used with PowerShell.
We’re currently working this out. We’d appreciate your feedback if this is of interest to your area.
Another interesting area that we’re currently working on is adding support for signing in with multiple identities. This is especially interesting for people connecting to and working with multiple tenants, for example those working at companies in the IT services industry. Switching between identities should be easy and not force a user to go through the entire login flow, time and time again.
We’ve currently working out ideas on this. If you’d like to pitch in on how this should be built, do come in and give us some feedback.
This release wouldn’t be possible without the help of (in alphabetical order):
- Adam Wójcik
- János Dojcsák
- Ganesh Sanap
- Jasey Waegebaert
- Martin Lingstuyl
- Mathijs Verbeeck
- Michał Kornet
- Michael Milton
- Milan Holemans
- Nanddeep Nachan
- Nico De Cleyre
- Saurabh Tripathi
- Smita Nachan
- Waldek Mastykarz
A warm welcome to this month’s new contributor!:
Thank you all for the time you chose to spend on CLI for Microsoft 365 and for your help to advance it!
CLI for Microsoft 365 wouldn’t be where it is today if it weren’t for our users who provide us with feedback. High fives to the following people who took the time to share their feedback and ideas for improvement with us (in alphabetical order):
CLI for Microsoft 365 is constantly growing and evolving. We’re always looking for ways to improve. There are still many areas not covered by the CLI as well as many amazing ideas for unique features the tool might provide. Your feedback will help us make the right decisions in which areas we should focus on. If you want to help out please do join the currently open discussions
Get the latest release of CLI for Microsoft 365 from npm by executing:
npm i -g @pnp/cli-microsoft365
Alternatively, you can get the latest release from Docker by executing:
docker run --rm -it m365pnp/cli-microsoft365:latest
If you need more help getting started or want more details about the commands, architecture, or project, go to aka.ms/cli-m365. If you see any room for improvement, please, don’t hesitate to reach out to us either on Discord, GitHub, or X.