In these challenging times, one might find themselves in a situation where they need to carry out operations upon their MicroSoft Office365 tenancies, on something else other that windows.
There is PowerShell, a hugely powerful way to administer Office365, but it will only run on windows, it also requires setting up, various modules have to be loaded, credentials managed moreover scripts have to be crafted taking time.
So I have found that I am in a situation using a Mac remotely. Office365 CLI provides versatile commands to administer the gamut of Office365 Apps from SharePoint to Teams.
Example, getting reports on teams for a given tenancy
o365$ teams team list
or a list of all site collections
o365$ spo site classic list
checking stats of a connection
o365$ status
issuing commands directly to the terminal piping out to a file
o365 teams team list > /Users/development/Desktop/teamsExample.txt
issuing commands directly to the terminal piping out to a json file
o365 teams team list > /Users/development/Desktop/teamsExample.json
Here’s what can be managed using Office365 CLI
Office 365 CLI v2.8.0 Manage Microsoft Office 365 and SharePoint Framework projects on any platform Commands: help [command...] Provides help for a given command. exit|quit Exits application. version Shows the current version of the CLI consent [options] Consent additional permissions for the Azure AD application used by the Office 365 CLI login [options] Log in to Office 365 logout [options] Log out from Office 365 status [options] Shows Office 365 login status Command Groups: aad * 35 sub-commands. accesstoken * 1 sub-command. cli * 5 sub-commands. flow * 12 sub-commands. graph * 5 sub-commands. onedrive * 7 sub-commands. outlook * 13 sub-commands. pa * 5 sub-commands. planner * 1 sub-command. skype * 3 sub-commands. spfx * 3 sub-commands. spo * 215 sub-commands. teams * 41 sub-commands. tenant * 4 sub-commands. util * 1 sub-command. yammer * 9 sub-commands.
Installation
Top tip, create an additional Mac User account with admin rights if you can to carry out all this work.
Goto https://brew.sh and follow the instructions to download HomeBrew on a Mac. You will need to paste the command in from the page into a Terminal prompt. I have not shown the command here as it has changed over time.
Once installed in the terminal window type
brew install node
Check node and npm are installed using the terminal by issuing
node -v
and
npm -v
The result is that you will see three part version numbers.
To install the Microsoft Office 365 CLI, follow the reference page’s instructions, ultimately typing the following in the terminal window.
npm install -g @pnp/office365-cli
Bonus installation, Linux
I have a raspberry pi, with Ubuntu 19.2 on it, Iwondered if the Office365 CLI would work on it? I issued the following commands in a terminal prompt. I haven’t tried this using ssh as it involves a step where we need to open a web browser to authenticate, so over secure shell or on a headless linux box that is going to be hard!
sudo apt install git sudo apt install curl
Then install a package manager for node e.g Homebrew or chocolatey if you like, since I prefer beer, I issued the following in a terminal prompt. You can ponder over chocolate of beer.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" `
After download and installation has completed type the following in the terminal session.
sudo apt-get install build-essential echo 'eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)' >> /home/osboxes/.profile eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv) brew install gcc
Now install node, type the following in a terminal
brew install node
So at this point we have node and crucially node package manager, npm, so we can install the Office365. CLI
Type the command into the terminal
npm install -g @pnp/office365-cli
To test type o365 at the terminal prompt, follow the instructions to authenticate using a web browser and the code, login with credentials we can now retrieve all the Sharepoint site collections using
spo site list
Example result…
Title | Url |
TestSite | https://abctenant.sharepoint.com/sites/Site |
TestSite1 | https://abctenant.sharepoint.com/sites/Site1 |
PlanA | https://abctenant.sharepoint.com/sites/PlanA |