cli-microsoft365-script

A guide for writing PowerShell scripts that use CLI for Microsoft 365, a command-line tool for managing Microsoft 365 services. It covers SharePoint, Entra ID, Teams, and related administration tasks.

In plain words
What is it for?
Use it to automate Microsoft 365 administration, including SharePoint provisioning, Entra ID users and groups, and Teams setup.
Why use it?
It provides consistent command-line settings and authentication steps so scripts can process structured output and handle errors predictably.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/pnp/cli-microsoft365-mcp-server/cli-microsoft365-script
Any agent
npx skills add pnp/cli-microsoft365-mcp-server --skill cli-microsoft365-script
Clone the repo
git clone --depth 1 https://github.com/pnp/cli-microsoft365-mcp-server

Made for: Claude Code, Codex.

Per session 85 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,438 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00085 $0.03438
Opus 5 $0.00043 $0.01719
Sonnet 5 $0.00017 $0.00688
Haiku 4.5 $0.00009 $0.00344

Measured 2d ago against content hash 8a07b7dcec28, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

cli-microsoft365-script scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.github/skills/cli-microsoft365-script/SKILL.md · 464 lines

How it starts

The opening of the file, as written. The whole thing — 464 lines — stays where its author put it; the contents beside it link to each section on GitHub.

CLI for Microsoft 365 — PowerShell Scripting

You are an expert at writing PowerShell scripts that use CLI for Microsoft 365 (m365) to automate Microsoft 365 management tasks. Follow these instructions when the user asks you to write a PowerShell script that uses CLI for Microsoft 365 commands.

Script Setup

Every PowerShell script using CLI for Microsoft 365 should start with proper configuration. Use this template as a starting point:

#!/usr/bin/env pwsh

$ErrorActionPreference = "Stop"

# Configure CLI for scripting
m365 cli config set --key "output" --value "json"
m365 cli config set --key "errorOutput" --value "stdout"
m365 cli config set --key "showHelpOnFailure" --value "false"
m365 cli config set --key "printErrorsAsPlainText" --value "false"
m365 cli config set --key "prompt" --value "false"
$env:CLIMICROSOFT365_NOUPDATE = "1"

# Ensure authentication
m365 login --ensure

Why these settings matter

Setting Value Purpose
output json Structured data for reliable parsing
errorOutput stdout Allows PowerShell to capture errors in variables
showHelpOnFailure false Prevents help text from polluting output
printErrorsAsPlainText false Returns errors as JSON for structured handling
prompt false Prevents interactive prompts that block automation

The $env:CLIMICROSOFT365_NOUPDATE = "1" environment variable disables update checks to avoid delays in automated scripts.

Authentication

Check and establish authentication

Always use m365 login --ensure at the start of every script. This command checks if you are already authenticated and only prompts for login if necessary:

    m365 login --ensure

Authentication for automation and CI/CD

For unattended scripts, use certificate-based or secret-based authentication:

    # Certificate-based (recommended for CI/CD)
    m365 login --authType certificate --certificateFile "C:\certs\app.pfx" --password $env:CERT_PASSWORD

    # Client secret
    m365 login --authType secret --secret $env:CLIENT_SECRET

    # Managed identity (Azure-hosted only)
    m365 login --authType identity

Read the full file on GitHub · 464 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 464 lines · 85 tokens per session scan A 8a07b7dcec28

Subscribe to this mod's changes

cli-microsoft365-script is a skill published in the GitHub repository pnp/cli-microsoft365-mcp-server (128 stars, last pushed 4d ago), licensed MIT. It adds 85 tokens to every session and 3,438 once invoked, about $0.0004 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

resume-builder

Generate professional resumes that conform to the Reactive Resume schema. Use when the user wants to create, build, or generate a resume through conversational AI, or asks about resume structure, sections, or content. This skill guides the agent to ask clarifying questions, avoid hallucination, and produce valid JSON…

amruthpillai/reactive-resume · 71 tokens

dependency-flow

MAUI-specific dependency flow rules, channel conventions, and feed lookup workflows. Use when asked about darc, BAR, Maestro, feeds for .NET MAUI, build promotion, asset lookup, channel mappings, or dependency flow for dotnet/maui. Wraps the maestro-cli skill and maestro MCP tools with MAUI-specific guardrails.

dotnet/maui · 71 tokens

pr-finalize

Finalizes any PR for merge by verifying title/description match implementation AND performing code review for best practices. Use when asked to "finalize PR", "check PR description", "review commit message", before merging any PR, or when PR implementation changed during review. Do NOT use for extracting lessons (use…

dotnet/maui · 92 tokens

ast-grep

Guide for writing ast-grep rules to perform structural code search and analysis. Use when users need to search codebases using Abstract Syntax Tree (AST) patterns, find specific code structures, or perform complex code queries that go beyond simple text search. This skill should be used when users ask to search for…

JanDeDobbeleer/oh-my-posh · 80 tokens

evaluate-pr-tests

Evaluates tests added in a PR for coverage, quality, edge cases, and test type appropriateness. Checks if tests cover the fix, finds gaps, and recommends lighter test types when possible. Prefer unit tests over device tests over UI tests. Triggers on: 'evaluate tests in PR', 'review test quality', 'are these tests…

dotnet/maui · 94 tokens

verify-tests-fail-without-fix

Verifies tests catch the bug. Auto-detects test type (UI tests, device tests, unit tests) and dispatches to the appropriate runner. Supports two modes - verify failure only (test creation) or full verification (test + fix validation).

dotnet/maui · 60 tokens