Office 365 CLI v2.1


We’ve just published a new version of the Office 365 CLI with new commands for working with and managing Office 365 tenants and SharePoint Framework projects on any platform.

Manage Office 365 and SharePoint Framework projects on any platform

Office 365 CLI is a cross-platform CLI that allows you to manage various configuration settings of Office 365 and SharePoint Framework projects no matter which operating system or shell you use.

While building solutions for Office 365 expands beyond the Windows operating system, managing many of the platform settings is possible only through PowerShell on Windows. As more and more users work on non-Windows machines, it’s inconvenient for them to have to use a Windows virtual machine to configure their tenants. With the Office 365 CLI, you can configure your tenant no matter which operating system you use. Additionally, using Office 365 CLI, you can manage your SharePoint Framework projects.

New version of Office 365 CLI - v2.1

Following our monthly release cadence, we’ve released a new version of the Office 365 CLI with some new capabilities.

Work with PowerApps components on any platform

One of the recent additions to PowerApps is the Components Framework (PCF) which allows developers to build reusable components that can encapsulate complex logic and allow less technically-savvy users to build powerful applications. PCF is powered by a CLI, which unfortunately works only on Windows.

For this release of the Office 365 CLI, Yannick Reekmans did a great job of porting the first pieces of the PCF CLI and support creating PCF projects and solutions on any platform. Our ambition is to enable developers on any platform to build PCF projects and we hope to close the gaps in the future releases of the Office 365 CLI.

Upgrade SharePoint Framework projects in different shells

Using the Office 365 CLI you can easily get a report of the steps necessary to upgrade your SharePoint Framework project to the specified SharePoint Framework version. The CLI doesn’t modify any of your project files but provides you with code snippets that you need to execute to upgrade your project files.

Originally, when we released this command, the report would contain upgrade scripts based on Bash. Many developers are however using either PowerShell or the Windows command line and to cater to them, for this release of the Office 365 CLI, Bassem Khalil contributed support for PowerShell and Windows command line in the spfx project upgrade command.

To get a report for upgrading your SharePoint Framework project to the latest version of the SharePoint Framework, suited for running in PowerShell, execute:

spfx project upgrade --shell powershell

To get upgrade instructions for the Windows command line, execute:

spfx project upgrade --shell cmd

For more information about upgrading SharePoint Framework projects using the Office 365 CLI, see the documentation.

Remove Microsoft Teams channels

More and more organizations use Microsoft Teams to facilitate collaboration and communication. As the adoption increases, some channels might become obsolete and cleaning them up can simplify finding the right information.

For this release of the Office 365 CLI, Garry Trinder contributed a command to remove Teams channels. To remove the specified Teams channel using the Office 365 CLI, execute:

teams channel remove --channelName 'channelName' --teamId d66b8110-fcad-49e8-8159-0d488ddb7656

For more information about managing Microsoft Teams using Office 365 CLI see the documentation at aka.ms/o365cli.

Add web parts to empty modern pages

As the adoption of modern SharePoint UI increases, so does the need to automate provisioning and automation scenarios. One of the common needs is the ability to provision pre-configured sites and pages.

For this release of the Office 365 CLI, Joakim Högberg contributed the ability to add web parts to empty pages. In the past, the CLI required you to create the necessary sections and columns first, but with Joakim’s changes, that’s no longer necessary and you can add web parts directly to empty pages.

For more information about managing modern pages using the Office 365 CLI see the documentation at aka.ms/o365cli.

Get access token for any resource

When building applications on the Microsoft cloud, developers can use the rich API set to interact with the different services and their data. To call these APIs, you need to first provide a valid access token. Especially when you’re just experimenting, it might be tedious to get it, and to make it easier, we’ve introduced a command to give you a valid access token for the specified resource. For example, to get an access token for the Microsoft Graph, execute:

accesstoken get --resource https://graph.microsoft.com

accesstoken get is a great utility command when experimenting with the different APIs on the Microsoft cloud.

Get content type hub URL

Organizations that use SharePoint for its Enterprise Content Management capabilities, often use the Content Type Hub to ensure the consistency of their metadata across their environment. To support building automation scenarios with the Content Type Hub, for this release of the Office 365 CLI, Stijn Brouwers added a command to retrieve the URL of the Content Type Hub site.

To get the URL of the Content Type Hub in your tenant, execute:

spo contenttypehub get

Contributors

This release wouldn’t be possible without the help of (in alphabetical order) Stijn Brouwers, Velin Georgiev, Joakim Högberg, Bassem Khalil, Patrick Lamber, Yannick Reekmans, Garry Trinder, Joseph Velliah, Rabia Williams. Thank you all for the time you chose to spend on the Office 365 CLI and your help to advance it!

Work in progress

Here are some things that we’re currently working on.

More commands, what else

Office 365 is evolving and new capabilities are being released every day. With the Office 365 CLI, we aim to help you manage your tenant on any platform in a consistent way, no matter which part of Office 365 you interact with. While we keep adding new commands to the Office 365 CLI each release, we still barely scratched the surface with what’s possible in Office 365. In the upcoming versions of the Office 365 CLI, you can expect us to add more commands across the different workloads in Office 365.

To make it easier for you to see how the CLI commands compare to the different PowerShell cmdlets, we’ve extended the comparison sheet with cmdlets for Flow, PowerApps, and Teams.

Script examples

In every release of the Office 365 CLI, we introduce new commands for managing Office 365. With 275 commands across the different Office 365 services, the Office 365 CLI has become a powerful tool, not just for managing your tenant but also for automating your daily work. In the coming weeks, we want to spend some time to show you how you can use the Office 365 CLI to build automation scripts in PowerShell Core and Bash. If you have any scripts using SPO or PnP PowerShell that you use frequently, please share them with us so that we can learn more about the common automation scenarios.

Welcome to the team Garry Trinder

We consider ourselves very lucky with nearly 40 contributors who, since the inception of the Office 365 CLI, chose to share their experience with the community and worked with us on new commands and improvements of the CLI. One of these contributors is Garry Trinder who’s been not only contributing CLI’s functionality but who’s also been helping others with their issues and questions. Garry will be helping Velin and myself to coordinate the Office 365 CLI project. Great to have you with us, Garry!

Try it today

Get the latest release of the Office 365 CLI from npm by executing in the command line:

npm i -g @pnp/office365-cli

If you need more help getting started or want more details about the commands, the architecture or the project, go to aka.ms/o365cli. If you see any room for improvement, please, don’t hesitate to reach out to us either on GitHub, on twitter with the #office365cli hashtag or on gitter.

Others found also helpful: