Office 365 CLI Overview
Microsoft technology stack is well known to be supported on Windows operating system. PowerShell has been developer and administrators best friend in Office 365 to execute powerful commands and automate the process. However PowerShell is only supported on windows platform.
Office 365 CLI helps to manage the Office 365 tenant and SharePoint framework (SPFx) projects on any platform. It can work well on Windows, Linux, or macOS. Office 365 CLI is supported on PowerShell, Cmder, and Bash. Office 365 CLI also supports to build automation scripts.
In this article, we will see how to install Office 365 CLI and use it to manage Office 365 and SharePoint Framework projects.
Installing Office 365 CLI
Office 365 CLI is available as NPM package.
Use below command to install Office 365 CLI globally:
npm i -g @pnp/office365-cli
To install the beta version of Office 365 CLI, use below command:
npm i -g @pnp/office365-cli@next
How to use Office 365 CLI
Once the installation is finished, we can start using Office 365 CLI by typing office365 on the command line:
This will start the Office 365 CLI with its own command prompt:
Managing Office 365 Tenant
To login to the Office 365 tenant, use below command.
o365$ spo login https://[tenant]-admin.sharepoint.com
Replace the token
[tenant]in the above command with your Office 365 tenant name.
Depending upon which settings you would like to manage, specify tenant admin site (i.e. -admin) or regular SharePoint site.
The command will return a code to authenticate. The code is generated unique each time. Copy the code for future reference.
Open url (https://microsoft.com/devicelogin) in the browser.
Type in the code.
- Click Continue.
Enter Office 365 credentials or select from list.
The app will require permission on Office 365 tenant.
- Click Accept to grant the permissions.
Once the permission is granted, you will be signed in to PnP Office 365 management shell application from your device.
- You may close the browser window.
- Return back to the command prompt.
Office 365 CLI Prompt
To get list of all available commands, type below command.
The aad* commands helps to work with Azure AD.
The azmgmt* commands helps to work with Azure Management Service.
The graph* commands helps to work with Microsoft graph.
The SPFx* commands helps to manage SharePoint Framework projects.
The only available command at the time of writing this article helps to upgrade the SharePoint Framework projects to the newer versions.
The SPO* (SharePoint Online) commands helps to manage SharePoint Online site.
To exit the CLI, type below command:
Upgrading Office 365 CLI
As Office 365 CLI is available as NPM package, the bug fixes and newer functionalities are released as a new version of NPM package.
Run below command to see, if Office 365 CLI needs upgrade:
npm outdated --global
To update the Office 365 CLI, run below command:
npm update -g @pnp/office365-cli
Office 365 CLI helps to manage the Office 365 tenant and SharePoint framework (SPFx) projects on any platform. It can be used effectively to upgrade SPFx projects and build automation scripts.
This content was originally posted here.
Leave a comment