Getting Started with the Cross-Platform CLI for Microsoft 365
Welcome back, listeners and readers! If you have ever found yourself buried under a mountain of repetitive administrative tasks in the Microsoft 365 admin center, clicking through endless menus just to provision a site or update a user property, this guide is specifically for you. Modern cloud administration demands speed, scalability, and precision. Gone are the days when a true systems administrator or developer relied solely on graphical user interfaces for managing sprawling enterprise environments. Today, we embrace the power of the command line. In this comprehensive deep-dive, we are going to explore the cross-platform CLI for Microsoft 365—a tool that is rapidly becoming the secret weapon for IT pros, developers, and consultants who want to reclaim their time and automate their workflows.
This blog post serves as an extended companion to our latest podcast episode, Automate Microsoft 365 with the Cross-Platform CLI. If you enjoy the concepts we break down below, make sure to head over and give that episode a full listen for additional tips, tricks, and banter!
Introduction to the Cross-Platform CLI for Microsoft 365
Before we dive into the installation wizardry and authentication steps, let us take a moment to understand what the CLI for Microsoft 365 actually is and why it deserves a permanent home in your administrative toolbelt. At its core, the CLI for Microsoft 365 is a versatile, open-source command-line interface that allows you to manage various settings and data across your Microsoft 365 tenant. What makes it uniquely powerful is right there in the name: it is cross-platform. Whether you are running Windows on your main workstation, swearing by macOS for your daily development, or running a lean Linux distribution on a server or container, the CLI for Microsoft 365 behaves consistently across all of them.
Historically, Microsoft administrators often had to juggle multiple disparate tools. You would use Azure PowerShell for Azure Active Directory tasks, SharePoint PnP PowerShell for your SharePoint Online provisioning, and perhaps entirely different Graph API calls or custom scripts for other services. The CLI for Microsoft 365 bridges these gaps by providing a unified syntax. It leverages the Microsoft Graph API under the hood, wrapping complex REST requests into intuitive, human-readable commands. Furthermore, because it is node-based and open-source, it boasts a vibrant community constantly contributing new features, bug fixes, and extensions. Whether you are managing SharePoint sites, Microsoft Teams, Azure AD users, or Power Platform environments, this tool offers a single pane of glass right inside your terminal.
Installing the CLI on Windows, macOS, and Linux
Getting the CLI up and running on your machine is remarkably straightforward, regardless of your operating system of choice. Because the tool is built using Node.js, the primary prerequisite is having a modern, stable version of Node.js installed on your system. We generally recommend installing the LTS (Long Term Support) version of Node.js to ensure maximum compatibility and stability.
Installing on Windows
If you are on Windows, you have a couple of fantastic options. You can use Windows PowerShell, PowerShell 7, or the Windows Command Prompt. Once you have Node.js installed, open your terminal of choice with administrative privileges and run the following command:
npm install -g @pnp/cli-microsoft365
The -g flag ensures that the CLI is installed globally on your system, making the m365 command accessible from any directory within your terminal. The installation process will download the necessary packages, compile any required binaries, and register the command paths. Once complete, you can verify the installation simply by typing m365 and pressing enter, which should display the core help menu and version information.
Installing on macOS
Mac users will find the experience identical, leveraging the power of the Terminal or alternative terminal emulators like iTerm2. Open your terminal application and ensure Node.js is installed—many Mac developers use Homebrew to manage their Node environments. Run the global installation command:
npm install -g @pnp/cli-microsoft365
Depending on your system permissions and how Node.js was originally installed, you might encounter a permission error. If that happens, you can either reconfigure your Node installation path to avoid permission issues or, as a last resort, prepend sudo to the command (though proper Node permission management is always the best practice). After a successful run, test your installation by typing m365 --version to confirm you are running the latest release.
Installing on Linux
For our Linux enthusiasts running Ubuntu, Fedora, Debian, or other distributions, the process is equally seamless. Assuming Node.js and npm have been installed via your package manager or Node Version Manager (NVM), run:
sudo npm install -g @pnp/cli-microsoft365
Linux environments frequently use the CLI for Microsoft 365 inside automated CI/CD pipelines, Docker containers, and Azure DevOps agents. Its lightweight nature and minimal resource footprint make it an ideal companion for headless automation servers where running a full graphical administrative suite is neither feasible nor desirable.
Configuring Your Environment for Success
Now that you have successfully installed the CLI on your machine, it is time to do a little bit of environment tuning to ensure your administrative experience is as smooth and secure as possible. The CLI for Microsoft 365 is designed to work out of the box, but taking a few minutes to configure your preferences can save you hours of troubleshooting down the line.
First, let us talk about output formats. By default, the CLI often outputs data in a clean JSON format, which is fantastic if you are piping data into other scripts, parsing it with tools like jq, or building automated pipelines. However, if you are sitting at your terminal and want to quickly read a list of users or sites, JSON can sometimes feel a bit verbose. You can configure the default output format using the config commands. For instance, you can set your preferred output to table format for better human readability during interactive sessions:
m365 config set --key output --value text
Additionally, you should explore the auto-completion features. The CLI supports auto-completion for PowerShell, Bash, and Zsh. Setting up tab-completion is an absolute game-changer. Imagine typing m365 sp and pressing the Tab key to automatically cycle through available SharePoint commands. To enable auto-completion for your specific shell, you can run the configuration command provided in the official documentation, which injects the necessary completion scripts into your profile.
Security is another critical aspect of environment configuration. Because the CLI has the potential to wield significant administrative power over your tenant, you should be mindful of where your configuration files and tokens are stored. The tool caches authentication tokens locally to prevent you from having to log in every single time you open a new terminal window. Ensure that your local machine disk is encrypted (using BitLocker on Windows or FileVault on macOS) and that you practice good hygiene by logging out or clearing your session cache when working on shared or temporary hardware.
Authenticating with Your Microsoft 365 Tenant
With the CLI installed and your environment configured, the next hurdle is authentication. How do we securely connect this command-line utility to our corporate Microsoft 365 tenant? The CLI for Microsoft 365 supports several authentication methods, catering to both interactive administrative sessions and automated unattended scripts.
Interactive Login
For your day-to-day interactive work, the easiest and most common way to authenticate is by using the standard login command:
m365 login
When you execute this command, the CLI will prompt you to open a web browser and navigate to a specific URL, providing a unique device code. This is the standard OAuth device code flow. Once you enter the code in your browser, you will be asked to sign in with your corporate Microsoft 365 credentials, complete any Multi-Factor Authentication (MFA) challenges required by your organization's conditional access policies, and grant the CLI permission to act on your behalf based on the requested scopes.
Once authenticated successfully, the terminal will confirm your login, displaying your user principal name and the tenant ID you are currently connected to. To verify your connection status at any time, you can simply run:
m365 status
This command is invaluable when you are jumping between multiple tenants or scripting environments, as it reassures you that you are targeting the correct environment before executing destructive or high-impact commands.
Service Principal and Certificate Authentication
What if you are building an automated pipeline—such as a GitHub Action, an Azure DevOps pipeline, or a scheduled Azure Function—that needs to run without human intervention? Interactive device code login will not work there. For these scenarios, the CLI supports authentication via Azure AD App Registrations (Service Principals).
You can authenticate using a client ID and client secret, or even more securely, using an Azure AD application certificate:
m365 login --authType certificate --appId YOUR_APP_ID --thumbprint YOUR_CERT_THUMBPRINT --tenant YOUR_TENANT.onmicrosoft.com
By leveraging service principals, you can adhere to the principle of least privilege, granting the CLI app registration only the specific API permissions it needs to complete its automated tasks—such as reading user profiles or provisioning specific site collections—without giving it blanket global administrator access.
Running Your First Administrative Commands
Now comes the fun part! You are installed, configured, and authenticated. Let us run a few basic commands to see the CLI for Microsoft 365 in action and prove just how much faster it is than clicking through the web GUI.
Let us start with something simple: retrieving a list of users from your Azure Active Directory / Entra ID tenant. Instead of navigating to the Azure Portal, opening Microsoft Entra ID, clicking on Users, and waiting for the list to load, you can simply type:
m365 aad user list
Boom! Instantly, your terminal fills with user data. If you want to filter that list to find a specific user, you can add query parameters or pipe the output. For example, if you want to find users from a specific department, the CLI allows you to filter results cleanly.
Next, let us look at SharePoint Online. Suppose you need to create a new modern communication site for a new project team. Doing this via the SharePoint admin center requires multiple clicks, filling out forms, setting owners, and waiting. With the CLI, you can script this in a single, repeatable command:
m365 spo site add --type CommunicationSite --title "Project Falcon" --url https://yourtenant.sharepoint.com/sites/projectfalcon --owner admin@yourtenant.onmicrosoft.com
Think about the implications of this. You can wrap that single command into a shell script alongside other commands that provision Microsoft Teams, assign licenses, and add users to security groups. Suddenly, onboarding a new department or spinning up a project space goes from a tedious two-hour manual chore to a five-second automated script execution.
You can also explore Microsoft Teams administration. Want to list all teams in your organization? Try running:
m365 teams team list
The breadth of modules supported by the CLI is staggering. Whether you are managing Power Apps, Power Automate flows, Exchange Online settings, or Planner tasks, the command structure remains intuitive and consistent: m365 [service] [resource] [action].
Conclusion and Next Steps
As we have explored in this guide, the cross-platform CLI for Microsoft 365 is far more than just another administrative tool—it is a paradigm shift in how you interact with your cloud environment. By moving away from click-ops and embracing command-line automation, you unlock unprecedented levels of efficiency, consistency, and scalability. Whether you are installing it on Windows for quick troubleshooting, on macOS for daily development, or inside a Linux container for automated CI/CD pipelines, the CLI provides a unified, powerful interface to master your Microsoft 365 tenant.
Remember, this blog post is just the tip of the iceberg. To get an even deeper understanding of how to leverage this tool in real-world enterprise scenarios, master advanced scripting techniques, and hear discussions on automation strategies that management rarely talks about, make sure to listen to our companion podcast episode, Automate Microsoft 365 with the Cross-Platform CLI. Hit subscribe, leave a review, and start automating your administrative life today!