home / skills / openclaw / skills / m365-pnp-cli

m365-pnp-cli skill

/skills/thomyg/m365-pnp-cli

This skill helps you manage Microsoft 365 tenants and workloads using the official m365-pnp-cli, enabling quick administration across SharePoint, Teams, and

npx playbooks add skill openclaw/skills --skill m365-pnp-cli

Review the files below or copy the command above to add this skill to your agents.

Files (2)
SKILL.md
4.9 KB
---
name: m365-pnp-cli
description: CLI for Microsoft 365 - Manage Microsoft 365 tenant, SharePoint Online, Teams, OneDrive, and more. Official PnP (Patterns and Practices) CLI.
metadata:
  {
    "openclaw":
      {
        "requires":
          {
            "bins": ["m365"],
            "node": ">=20.0.0",
            "npmPackages": ["@pnp/cli-microsoft365"]
          },
        "install":
          [
            {
              "id": "node",
              "kind": "node",
              "package": "@pnp/cli-microsoft365",
              "label": "Install m365 CLI (npm)",
              "description": "Install the CLI for Microsoft 365 globally: npm install -g @pnp/cli-microsoft365"
            }
          ],
        "homepage": "https://pnp.github.io/cli-microsoft365",
        "repository": "https://github.com/pnp/cli-microsoft365",
        "author": "Microsoft PnP (Patterns and Practices)",
        "keywords": ["microsoft365", "m365", "sharepoint", "teams", "onenote", "outlook", "cli", "microsoft", "pnp"],
        "npmPackage": "@pnp/cli-microsoft365"
      }
  }
---

# m365-pnp-cli Skill

This skill provides access to the **CLI for Microsoft 365** – the official PnP (Patterns and Practices) tool for Microsoft 365 management.

## ⚠️ IMPORTANT FOR AGENTS

**When in doubt, ALWAYS call `m365 --help` first to see all possibilities!**

```bash
# Always call help when unsure!
m365 --help

# For specific commands:
m365 login --help
m365 spo --help
m365 teams --help
```

## Installation

The CLI must be installed:
```bash
npm install -g @pnp/cli-microsoft365
```

Or use npx (sandbox):
```bash
npx @pnp/cli-microsoft365 --help
```

## Source & Verification

- **NPM Package:** https://www.npmjs.com/package/@pnp/cli-microsoft365
- **GitHub Repo:** https://github.com/pnp/cli-microsoft365
- **Documentation:** https://pnp.github.io/cli-microsoft365
- **Author:** Microsoft PnP (Patterns and Practices Community)

## What can the CLI do?

### Supported Workloads
- Microsoft Teams
- SharePoint Online
- OneDrive
- Outlook
- Microsoft To Do
- Microsoft Planner
- Power Automate
- Power Apps
- Microsoft Entra ID
- Microsoft Purview
- Bookings
- And more...

### Authentication
- Device Code (default)
- Username/Password
- Client Certificate
- Client Secret
- Azure Managed Identity
- Federated Identity

## Commands (Overview)

### Login/Logout
```bash
m365 login                    # Device Code Login
m365 logout                  # Logout
m365 status                  # Check login status
```

### SharePoint Online (spo)
```bash
m365 spo site list           # List all sites
m365 spo site get --url <url>  # Get site details
m365 spo list list --webUrl <url>  # Lists in a site
m365 spo file list           # List files
m365 spo folder add          # Create folder
```

### Teams
```bash
m365 teams channel list       # List channels
m365 teams channel get       # Get channel details
m365 teams user list         # List team members
m365 teams chat list         # List chats
m365 teams meeting list      # List meetings
```

### OneDrive
```bash
m365 onedrive drive list    # OneDrive Drives
m365 onedrive file list     # List files
m365 onedrive file get      # Get file content
```

### Outlook
```bash
m365 outlook mail list       # List emails
m365 outlook calendar list   # List calendar events
```

### Planner
```bash
m365 planner task list       # Planner Tasks
m365 planner plan get        # Get plan details
```

### Azure AD / Entra ID
```bash
m365 entra user list         # List users
m365 entra group list        # List groups
m365 entra app list          # List apps
```

## Usage as Assistant - IMPORTANT

### ⚡ First Step: ALWAYS call help!

```bash
# When in doubt - call help first!
m365 --help

# For specific commands:
m365 spo --help
m365 teams --help
m365 login --help
```

### Basic Usage

```bash
# Login (Device Code Flow)
m365 login

# Check status
m365 status

# SharePoint: List sites
m365 spo site list

# SharePoint: Get specific site
m365 spo site get --url "https://contoso.sharepoint.com/sites/test"

# Teams: List channels
m365 teams channel list --teamId <team-id>

# OneDrive: Files
m365 onedrive file list

# Outlook: Emails
m365 outlook mail list --folder Inbox

# Planner: Tasks
m365 planner task list
```

## Output Options

```bash
# As JSON (default)
m365 spo site list

# As text
m365 spo site list --output text

# Filter with JMESPath
m365 spo site list --query "[?Template==\`GROUP#0\`].{Title:Title, Url:Url}"
```

## Authentication

The CLI uses **Device Code Flow** by default:

```bash
m365 login
# → You'll receive a code on another device
# → Use that code to authenticate with Microsoft
```

For automated scripts, you can also use:
- **Certificate** (recommended for production)
- **Client Secret** (less secure)
- **Username/Password** (testing only)

## Important

- **WHEN IN DOUBT: call m365 --help!**
- **Login required** for most commands
- **JSON output** is easiest to parse
- **JMESPath** for efficient filtering
- CLI requires **Node.js >= 20**

Overview

This skill wraps the official PnP CLI for Microsoft 365, providing a command-line interface to manage Microsoft 365 tenants, SharePoint Online, Teams, OneDrive, Outlook, Entra ID, and other workloads. It enables scripted and interactive administration tasks, from listing sites and users to exporting resources and automating routine operations. The CLI is cross-platform and designed for both ad-hoc troubleshooting and integration into automation pipelines.

How this skill works

The skill calls the @pnp/cli-microsoft365 binary to run commands against Microsoft 365 services. It authenticates using Device Code Flow by default and supports alternate auth methods (certificate, client secret, managed identity) for automated scenarios. Commands return JSON by default for easy parsing, and output can be filtered with JMESPath or switched to text for human-readable output.

When to use it

  • Administer SharePoint Online sites, lists, files, and permissions from scripts or terminal.
  • Manage Teams data: list teams, channels, members, chats, and meetings.
  • Automate OneDrive and Outlook operations such as file retrieval and mail/calendar exports.
  • Query Entra ID for users, groups, and applications as part of audits or reports.
  • Integrate tenant management into CI/CD pipelines or scheduled backup tasks.

Best practices

  • Always run m365 --help or command-specific --help before executing unfamiliar commands.
  • Use JSON output and JMESPath filters for reliable parsing in automation scripts.
  • Prefer certificate-based authentication for production automation; use device code for interactive use.
  • Ensure Node.js >= 20 is installed and the CLI is updated to the latest release for security and feature fixes.
  • Limit scope and permissions of service principals used with the CLI to follow least privilege.

Example use cases

  • Script to list all SharePoint sites and export their URL and template to JSON for inventory.
  • Automated job that uses certificate auth to fetch OneDrive files and back them up nightly.
  • On-demand admin command to list Teams channels and export membership for compliance checks.
  • Query Entra users and groups to create a reconciliation report for HR onboarding/offboarding.

FAQ

How do I authenticate non-interactively for scheduled tasks?

Use certificate-based authentication or a managed identity. Certificates are recommended for production automation; client secrets are supported but less secure.

What output format should I use for scripts?

JSON is the default and easiest to parse programmatically. Use --query with JMESPath to filter fields before processing.