| name | m365-shared |
| description | CLI for Microsoft 365 (m365): shared patterns for authentication, installation, output formatting, and common flags. Use when user mentions "m365 login", "m365 setup", "đăng nhập Microsoft 365", "m365 status", "kết nối Microsoft", or when another m365-* skill needs auth/common pattern reference.
|
| allowed-tools | ["Bash","Read"] |
m365-shared — Shared Patterns
Installation Check
which m365
If not installed, ask user before installing:
npm i -g @pnp/cli-microsoft365
After install, verify:
m365 version
Authentication
Quick Check
m365 status
If not logged in, guide user through login:
m365 login
Default: device code flow — hiển thị mã code để xác thực qua trình duyệt. Muốn mở trình duyệt đăng nhập trực tiếp, dùng m365 login --authType browser.
For other auth methods (certificate, secret, device code), see references/authentication.md.
Verify Connection
m365 status -o json
Response includes: connectedAs, authType, appId, appTenant, cloudType.
Output Format
All m365 commands support:
| Flag | Description |
|---|
-o, --output [format] | json (default), text, csv, md, none |
--query [jmespath] | JMESPath client-side filter/projection |
--verbose | Verbose logging |
--debug | Debug logging |
Best Practices
Always use json output with --query to minimize token usage:
m365 teams team list -o json
m365 teams team list -o json --query '[].{id:id, name:displayName}'
JMESPath Patterns
--query '[].{id:id, name:displayName}'
--query "[?visibility=='Public'].{id:id, name:displayName}"
--query '[0]'
--query 'length(@)'
--query '[].{id:id, email:owner.email}'
ID Lookup Workflow
Most m365 commands need IDs (team ID, channel ID, site URL, etc.). General pattern:
- List resources to find the ID
- Use the ID in subsequent commands
m365 teams team list --joined -o json --query "[?contains(displayName,'Project')].{id:id, name:displayName}"
m365 teams channel list --teamId "TEAM_ID" -o json --query '[].{id:id, name:displayName}'
Error Handling
Common errors and solutions:
| Error | Cause | Solution |
|---|
You're not logged in | No active session | Run m365 login |
Access denied | Insufficient permissions | Check required permissions in --help |
Resource not found | Wrong ID or URL | Verify resource exists via list command |
Request throttled | Too many requests | Wait and retry |
Security Rules
- NEVER output tokens, secrets, or credentials in responses
- Confirm with user before any destructive operation (remove, delete)
- Prefer
--output none for write operations when response is not needed
- Use
--query to exclude sensitive fields from output