Tag: Office365

Today i’m gonna show you how to install the Office 365 CLI. but wait , why should i invest time in this if i have all these good cmdlets for my powershell in Windows ? Well first off, if you are using something else than Windows the Office 365 CLI will come in handy straight away, but another strong feature is that you can call the Office 365 CLI commands from any scripting language. Yeah you read that right, you can make a bash, powershell, python script and so on. This is also usefull if your team consist of devops with diffrent types of operating systems. With this CLI you can make the same script that works cross-platform. It also presist your connection to your tenant when authenticated. Pretty neat.

To install the Office 365 CLI type the following

npm i -g @pnp/office365-cli

Now lets try to authenticate to our tenant. (Replace the URL with your sharepoint admin url)

o365 spo login https://m365x544796-admin.sharepoint.com

This will return something like this: To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code C52LX32VC to authenticate. Now you will need to open a browser, enter the url and paste the code. This will authenticate your device.

https://microsoft.com/devicelogin

Paste in the temporary code presented from the CLI

You now need to authenticate with a global admin account, and accept permissions requested by the CLI.

Remember, the Office 365 CLI persists connection information on your computer so you dont have to authenticate every time you run a script. Now your ready to mange your Office 365 tenant from almost any shell/scripting language, happy automation!

If you want to uninstall the Office 365 CLI and have already connected to your tenant you should logout of it or else the the login information will presist on your computer and you have to remove it manually.

o365 spo logout https://m365x544796-admin.sharepoint.com

To logout of our tenant (Replace the URL with your sharepoint admin url)