Office 365 CLI v1.10.0


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 the Office 365 CLI, you can manage your SharePoint Framework projects.

New version of Office 365 CLI - v1.10.0

New version of the Office 365 CLI with new and improved commands for managing your Office 365 tenant.

Easily add API permissions

Using API permissions, tenant administrators can allow developers to securely communicate with APIs secured with Azure AD. In larger organizations, managing API permissions manually is tedious, and doing it in a scripted way saves you times and headaches. In the previous versions of the Office 365 CLI, you could manage API permissions by directly manipulating the SharePoint service principal. With the recent addition to the SharePoint APIs, granting API permissions became easier.

To grant API permissions, instead of manipulating the Azure AD service principal, simply execute:

spo serviceprincipal grant add --resource 'Microsoft Graph' --scope 'Mail.Read'

You can also execute the command, using its shorter alias sp:

spo sp grant add --resource 'Microsoft Graph' --scope 'Mail.Read'

For more information about managing API permissions using the Office 365 CLI, see the documentation at aka.ms/o365-cli.

Update existing list- or site columns

Columns in SharePoint are the foundation of storing the content’s metadata. All SharePoint solutions rely to some degree on custom columns, no matter if they’re provisioned to lists or sites. In this version of the Office 365 CLI, we’ve added support for creating new list- and site columns and retrieving information about existing columns.

To update the title of the existing list column and push updates to lists, execute:

spo field set --webUrl https://contoso.sharepoint.com/sites/project-x --name 'MyColumn' --updateExistingLists --Title 'My column'

For more information about working with list- and site columns using the Office 365 CLI, see the documentation at aka.ms/o365-cli.

Manage list content types

Content types in SharePoint simplify managing content and its metadata. Before content types can be used, they must be assigned to lists and libraries. For this release of the Office 365 CLI, Paweł Hawrylak contributed a set of commands to manage list content types.

To add an existing content type to a list, execute:

spo list contenttype add --webUrl https://contoso.sharepoint.com/sites/project-x --listTitle Documents --contentTypeId 0x0120

To see, which content types are configured on the particular list, execute:

spo list contenttype list --webUrl https://contoso.sharepoint.com/sites/project-x --listTitle Documents

Finally, to remove a content type from a list, execute:

spo list contenttype remove --webUrl https://contoso.sharepoint.com/sites/project-x --listTitle Documents --contentTypeId 0x010109010053EE7AEB1FC54A41B4D9F66ADBDC312A

For more information about managing list content types using the Office 365 CLI, see the documentation at aka.ms/o365-cli.

Upload files

When provisioning SharePoint applications or managing your SharePoint environment, you might need to upload multiple files to different locations in SharePoint. Using a script, is a convenient and efficient way of doing it. Velin Georgiev contributed a command, that allows you to upload a file to the specified location in SharePoint.

To upload a file to SharePoint, execute:

spo file add --webUrl https://contoso.sharepoint.com/sites/project-x --folder 'Shared Documents' --path 'C:\MS365.jpg'

When uploading a file, you can also immediately specify values for the associated list columns:

spo file add --webUrl https://contoso.sharepoint.com/sites/project-x --folder 'Shared Documents' --path 'C:\MS365.jpg' --Title "New Title"

For more information about working with files using the Office 365 CLI, see the documentation at aka.ms/o365-cli.

Update list views

List views allow users to organize information stored in SharePoint lists and document libraries and easily find the required data. Using the SharePoint UI, users can configure views to meet their needs, configuring settings like which columns should be displayed or how the data should be sorted. If you need to change configuration of many list views or need to have a repeatable way of applying changes, you can do it using the Office 365 CLI.

To update list view’s title, execute:

spo list view set --webUrl https://contoso.sharepoint.com/sites/project-x --listTitle 'My List' --viewTitle 'All items' --Title 'All events'

To configure view formatter on the existing list view, execute:

spo list view set --webUrl https://contoso.sharepoint.com/sites/project-x --listTitle 'My List' --viewTitle 'All items' --CustomFormatter '`{"schema":"https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json","additionalRowClass": "=if([$DueDate] <= @now, 'sp-field-severity--severeWarning', '')"}`'

For more information about managing list views using the Office 365 CLI, see the documentation at aka.ms/o365-cli.

Manage webhooks

When building SharePoint applications, a common requirement is to be able to respond to activities in SharePoint, such as creating or editing a list item or document. In SharePoint Online, next to using Remote Event Receivers, you can use webhooks to get notified of changes in SharePoint content and configuration. For this release of the Office 365 CLI, Arjen Bloemsma continued his work on the support for webhooks, and contributed commands to update and remove webhooks.

To update a webhook, execute:

spo list webhook set --webUrl https://contoso.sharepoint.com/sites/ninja --listId 0cd891ef-afce-4e55-b836-fce03286cccf --id cc27a922-8224-4296-90a5-ebbc54da2e81 --notificationUrl https://contoso-functions.azurewebsites.net/webhook

To remove a webhook, execute:

spo list webhook remove --webUrl https://contoso.sharepoint.com/sites/ninja --listId 0cd891ef-afce-4e55-b836-fce03286cccf --id cc27a922-8224-4296-90a5-ebbc54da2e81

The extended support for managing webhooks using the Office 365 CLI, simplifies scenarios such as updating webhook notification URLs or refreshing webhooks that are about to expire.

For more information about managing webhooks using the Office 365 CLI, see the documentation at aka.ms/o365-cli.

Execute a search query

One of the most powerful SharePoint capabilities is Search. As the amount of content we create every day increases, finding the right information becomes more difficult. But SharePoint Search is not used exclusively by end-users. Executing specific search queries makes it possible to implement powerful automation scenarios. In this version of the Office 365 CLI, Stijn Brouwers contributed a command to execute a SharePoint Search query.

To find all documents using SharePoint Search, execute:

spo search --query 'IsDocument:1'

For more information about searching for content using the Office 365 CLI and examples, see the documentation at aka.ms/o365-cli.

Update site classification configuration

Office 365 allows you to enable classification for your SharePoint sites. This is an important capability that allows organization to improve their information security posture. For this release of the Office 365 CLI, Arjen Bloemsma contributed a command to update the site classification configuration.

To update the site classification configuration, execute:

graph siteclassification set --classifications "High, Medium, Low" --defaultClassification "Medium"

For more information about managing site classification using the Office 365 CLI, see the documentation at aka.ms/o365-cli.

Retrieve Microsoft Teams message

More and more organizations use Microsoft Teams to facilitate their internal communication. Not surprisingly, more digital workplace solutions include Teams and provision a preconfigured set of teams and channels. For this version of the Office 365 CLI, Arjen Bloemsma contributed a command to retrieve a message from Microsoft Teams.

To retrieve a message from Microsoft Teams, execute:

graph teams channel message get --teamId 5f5d7b71-1161-44d8-bcc1-3da710eb4171 --channelId 19:88f7e66a8dfe42be92db19505ae912a8@thread.skype --messageId 1540747442203

For more information about managing Microsoft Teams using the Office 365 CLI, see the documentation at aka.ms/o365-cli.

Contributors

This release wouldn’t be possible without the help of (in alphabetical order) Arjen Bloemsma, Stijn Brouwers, Velin Georgiev and Paweł Hawrylak. 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.

Setup script for the PnP SharePoint Starter Kit

A while back already, the SharePoint PnP team released the SharePoint Starter Kit: an end-to-end solution illustrating how to use the latest capabilities to build a modern intranet on Office 365. This starter kit will keep evolving as new capabilities are added to Office 365.

To help you setup the solution in your tenant, the PnP team released a setup script based on PnP PowerShell. Due to the current limitations of PnP PowerShell this script can be used only on Windows.

What if we had an equivalent script built in bash, using the Office 365 CLI which you could use on any platform?

I’ve already started working on this script in a separate repo. The basic structure is almost in place and ready for external contributions. Would you be interested in helping out with it?

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.

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: