Last Update: Sep 04, 2024 | Published: Dec 04, 2017
Office 365 CLI (“Command-Line Interface”) is a new open source tool that was incubated within the Office Developer Patterns and Practices (Office Dev PnP for short) group. The purpose of the tool is to allow administrators to view and change settings in Office 365, although for now, the tool is limited to SharePoint Online only.
Currently, the tool can be used to connect with a specific SharePoint Online site, to change and review settings for CDN, SharePoint customizations known as apps (or add-ins depending which documentation you’re following), and storage settings. Although this leaves a lot to be desired, it’s still a good start as the tool is cross-platform and can be used in Linux and macOS as well.
The tool is distributed as a pre-compiled package and can be installed easily with the npm tool. This is a package manager, which is not installed by default in Windows or other OS’s. You first need to either download npm or install it through your operating system’s package manager.
I’m using a virtual machine with Ubuntu Linux and it did not have npm installed with the basic installation. The quickest way to install npm is to execute the following command. Note that I’m using sudo to elevate my privileges for the installation to succeed:
sudo apt install npm
This takes a minute or so to install. You can try out if npm works now with:
sudo npm --version
You should see the version number. For me, it is 3.5.2.
I can now install Office 365 CLI by simply fetching the latest release via npm:
npm i -g @pnp/office365-cli
The ‘i’ parameter is a shorthand for install and -g is a shorthand for global. After installation succeeds, the tool can be executed by typing
office365
I have to admit, I felt a bit funny when first initiating this command on a Linux shell as it so strongly underlines how the world is changing with regards to Microsoft’s stance and technologies.
Using the tool is very straightforward. Once the tool starts, you can type help to get a list of all available commands. For now, there are only a few commands available but I expect this list to grow in the coming weeks and months. As the tool is open sourced, anyone can push their own ideas to the team or implement new functionality to be considered as part of the tool. See more information about the process here.
To connect to my SharePoint Online admin tenant, I use the following command:
spo connect https://{tenant-name}-admin.sharepoint.com
This initiates a clever authentication approach, where I use https://aka.ms/devicelogin in a browser to complete the authentication. I’ve recorded a screen capture of this process:
Once I ask for the connection, I receive a one-time passcode to use. Don’t worry, the one you’re seeing above is already used. From the browser side, this is how it looks:
I can now start querying for information from my tenant. With spo status, I can easily retrieve the access token and refresh token for authentication in my own apps.
With spo app list, I can view which apps have been deployed to my App Catalog within the SharePoint Online tenant. In my test tenant I only have one.
To further query this app, I can type spo app get -i and append the app id:
Other things the tool is capable of doing include adding and deploying apps, retracting and uninstalling apps, upgrading existing apps, configuring CDN settings, and retrieving and setting storage options for the tenant.
As the installation is so easy, I see this tool as highly useful even in its infancy for IT Pros and SharePoint Online admins. The ability to quickly verify settings in SharePoint Online and the ability to install new custom apps in a more controlled fashion is a very welcomed addition. Granted, we can still use PowerShell and the fabulous Office Dev PnP cmdlets but they are more problematic when not using Windows where PowerShell is natively baked in.
I recommend readers to keep a close eye on how this tool evolve, and to be vocal about your needs, possible bugs you might find, and provide feedback to the team building it.