Using PnP Office 365 CLI in Azure Shell

At the European SharePoint Conference 2017 in the Hackathon results session, Waldek Mastykarz from the PnP team announced the Office365 CLI which gives you the ability to manage an Office 365 on any platform.

We had the idea to run this inside the Azure Shell, giving you the ability to manage the Office 365 platform on any device including mobile Azure app. Awesome!

Initially, this proved to be challenging at the start because running the npm install with the global flag generates an permissions denied error and the command requires elevation.


Example connection error when running the NPM install command


It doesn’t appear to be a feature of the shell to let the user elevate so we were stuck on installing this package; but we managed to find another Microsoft resource to change the NPM config and run the installation and the Office 365 CLI in the Azure Shell.

Let’s get going…

In order to run these commands, you need to have an Azure subscription and have the cloud shell setup. Its best to run this setup on a computer rather than inside the Shell on a mobile device.

Open the Azure Shell and run these commands:

mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
nano ~/.bashrc
export PATH="$HOME/.npm-global/bin:$PATH"

Restart the Cloud Shell

npm i -g @pnp/office365-cli

To test:

spo connect

In Edge:

Azure Shell Office 365 CLI
Example running the Office 365 CLI in Edge

On iOS:


Example running Office 365 CLI on iOS Azure App



The credit for most of the operation goes to the Azure MS PnP team that had an article for installing the Azure Building Blocks into a Azure Shell. We adapted this for the Office 365 CLI based on this post:

Next steps

To see more:



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s