| name | m365-sharepoint |
| description | Trigger this skill for SharePoint Online — PRIMARILY the documents shared inside a GROUP/TEAM: the files in a team's "Shared Documents" library (the Files tab in Teams), said as "tài liệu nhóm", "tài liệu/file chia sẻ trên nhóm/team", "file của team X", "file trong nhóm", "Shared Documents", "thư viện tài liệu". Also covers SharePoint lists & list items, site files/folders (upload/download/checkin/checkout/copy/move), permissions, and creating sites. Fire whenever a request targets a TEAM/GROUP's files or a SharePoint site — đọc/list, tải lên (upload), tạo/xóa file & folder, tạo list, thêm item, chia sẻ link, phân quyền. Casual or unaccented phrasing still counts. This is SHARED/organizational storage, NOT personal — send the user's own private OneDrive ("onedrive của tôi", "lên onedrive cá nhân") to m365-onedrive. For Teams chat/channels/members (gửi tin nhắn, tạo channel, thành viên team) use m365-teams; for Google Drive use gws-drive.
|
| allowed-tools | ["Bash","Read"] |
m365-sharepoint — SharePoint Online Management
Prerequisites
which m365 || echo "Chưa cài m365 CLI. Chạy: npm i -g @pnp/cli-microsoft365"
m365 status || echo "Chưa đăng nhập. Chạy: m365 login"
For auth details, see ../m365-shared/references/authentication.md.
Operating Principles
- All commands require
--webUrl pointing to the SharePoint site URL
- Output: always
-o json with --query
- List/library identification: prefer
--listTitle for readability, --listId when title is ambiguous
- File/folder URLs: can be server-relative (
/sites/project/Shared Documents/file.pdf) or site-relative (Shared Documents/file.pdf)
- Destructive operations (remove, delete): always confirm with user first
1. Sites
Trường hợp phổ biến nhất là truy cập tài liệu của một nhóm/team bạn là thành viên (KHÔNG cần quyền admin). Resolve site URL của nhóm qua Graph rồi dùng làm SITE_URL cho mục 4. Files / 5. Folders. Tài liệu nhóm nằm trong thư viện "Shared Documents" (tab Files trong Teams).
Resolve Team/Group Site URL (non-admin)
m365 teams team list --joined -o json --query '[].{id:id, name:displayName}'
m365 request --url 'https://graph.microsoft.com/v1.0/groups/<GROUP_ID>/sites/root?$select=webUrl' -o json --query 'webUrl'
List Sites (admin)
spo site list cần quyền SharePoint Administrator — user thường nhận lỗi Unauthorized. Để làm việc với tài liệu nhóm, dùng cách resolve site qua group ở trên.
m365 spo site list -o json --query '[].{url:Url, title:Title, template:Template}'
m365 spo site list --type TeamSite -o json --query '[].{url:Url, title:Title}'
m365 spo site list --type CommunicationSite -o json --query '[].{url:Url, title:Title}'
m365 spo site list --filter "Url -like 'project'" -o json --query '[].{url:Url, title:Title}'
Get Site Details
m365 spo site get --url "https://contoso.sharepoint.com/sites/project" -o json
Create Site
m365 spo site add --type TeamSite --title "New Project" --alias "new-project" \
--description "Project collaboration site" -o json
m365 spo site add --type CommunicationSite --title "Company News" \
--url "https://contoso.sharepoint.com/sites/company-news" -o json
m365 spo site add --type TeamSite --title "HR Team" --alias "hr-team" \
--owners "admin@contoso.com" -o json
m365 spo site add --type ClassicSite --title "Archive" \
--url "https://contoso.sharepoint.com/sites/archive" \
--timeZone 4 --wait -o json
2. Lists
List All Lists
m365 spo list list --webUrl "SITE_URL" -o json \
--query '[].{id:Id, title:Title, items:ItemCount, template:BaseTemplate}'
m365 spo list list --webUrl "SITE_URL" --filter "BaseTemplate eq 100" -o json \
--query '[].{id:Id, title:Title}'
Get List Details
m365 spo list get --webUrl "SITE_URL" --title "Tasks" -o json
m365 spo list get --webUrl "SITE_URL" --id "LIST_GUID" -o json
m365 spo list get --webUrl "SITE_URL" --title "Tasks" --withPermissions -o json
Create List
m365 spo list add --webUrl "SITE_URL" --title "Project Tasks" --baseTemplate GenericList -o json
m365 spo list add --webUrl "SITE_URL" --title "Project Docs" --baseTemplate DocumentLibrary -o json
m365 spo list add --webUrl "SITE_URL" --title "Contracts" --baseTemplate DocumentLibrary \
--enableVersioning true --majorVersionLimit 50 -o json
m365 spo list add --webUrl "SITE_URL" --title "Team Events" --baseTemplate Events -o json
Common --baseTemplate values: GenericList, DocumentLibrary, Events, Tasks, Contacts, Announcements, Links, Survey, IssuesTracking.
3. List Items
List Items
m365 spo listitem list --webUrl "SITE_URL" --listTitle "Tasks" -o json \
--query '[].{id:Id, title:Title, status:Status}'
m365 spo listitem list --webUrl "SITE_URL" --listTitle "Tasks" \
--fields "Title,Status,AssignedTo,DueDate" -o json
m365 spo listitem list --webUrl "SITE_URL" --listTitle "Tasks" \
--filter "Status eq 'In Progress'" -o json \
--query '[].{id:Id, title:Title, assignee:AssignedTo}'
m365 spo listitem list --webUrl "SITE_URL" --listTitle "Tasks" \
--pageSize 100 --pageNumber 0 -o json
m365 spo listitem list --webUrl "SITE_URL" --listTitle "Tasks" \
--camlQuery "<View><Query><Where><Eq><FieldRef Name='Status'/><Value Type='Text'>Done</Value></Eq></Where></Query><RowLimit>10</RowLimit></View>" -o json
Get Item
m365 spo listitem get --webUrl "SITE_URL" --listTitle "Tasks" --id 42 -o json
Add Item
m365 spo listitem add --webUrl "SITE_URL" --listTitle "Tasks" \
--Title "New task" --Status "Not Started" --DueDate "2025-03-01 09:00:00" -o json
m365 spo listitem add --webUrl "SITE_URL" --listTitle "Tasks" \
--contentType "Task" --Title "New task" -o json
NOTE: DateTime fields must use local timezone format yyyy-MM-dd HH:mm:ss (NOT ISO 8601/UTC).
Update Item
m365 spo listitem set --webUrl "SITE_URL" --listTitle "Tasks" --id 42 \
--Status "In Progress" --AssignedTo "[{'Key':'i:0#.f|membership|user@contoso.com'}]" -o json
Delete Item
m365 spo listitem remove --webUrl "SITE_URL" --listTitle "Tasks" --id 42 --force
4. Files
List Files
m365 spo file list --webUrl "SITE_URL" --folderUrl "Shared Documents" -o json \
--query '[].{name:Name, size:Length, modified:TimeLastModified}'
m365 spo file list --webUrl "SITE_URL" --folderUrl "Shared Documents/Reports" -o json \
--query '[].{name:Name, size:Length}'
m365 spo file list --webUrl "SITE_URL" --folderUrl "Shared Documents" --recursive -o json \
--query '[].{name:Name, path:ServerRelativeUrl, size:Length}'
m365 spo file list --webUrl "SITE_URL" --folderUrl "Shared Documents" \
--filter "substringof('.pdf',Name)" -o json --query '[].{name:Name}'
Upload File
m365 spo file add --webUrl "SITE_URL" --folder "Shared Documents" \
--path "/local/path/report.pdf" -o json
m365 spo file add --webUrl "SITE_URL" --folder "Shared Documents/Reports/2024" \
--path "/local/path/q4-report.pdf" -o json
m365 spo file add --webUrl "SITE_URL" --folder "Shared Documents" \
--path "/local/path/file.pdf" --fileName "quarterly-report.pdf" -o json
m365 spo file add --webUrl "SITE_URL" --folder "Shared Documents" \
--path "/local/path/contract.docx" --checkOut true --checkInComment "Initial upload" -o json
Download File
m365 spo file get --webUrl "SITE_URL" --url "Shared Documents/report.pdf" \
--asFile --path "/local/download/report.pdf"
Copy File
m365 spo file copy --webUrl "SITE_URL" \
--sourceUrl "Shared Documents/report.pdf" \
--targetUrl "/sites/archive/Shared Documents" -o json
m365 spo file copy --webUrl "SITE_URL" \
--sourceUrl "Shared Documents/report.pdf" \
--targetUrl "/sites/other-site/Shared Documents" \
--nameConflictBehavior rename -o json
Move File
m365 spo file move --webUrl "SITE_URL" \
--sourceUrl "Shared Documents/old-folder/report.pdf" \
--targetUrl "/sites/project/Shared Documents/new-folder" -o json
Delete File
m365 spo file remove --webUrl "SITE_URL" --url "Shared Documents/unwanted.pdf" --force
Check In/Out
m365 spo file checkout --webUrl "SITE_URL" --url "Shared Documents/contract.docx"
m365 spo file checkin --webUrl "SITE_URL" --url "Shared Documents/contract.docx" \
--comment "Updated section 3"
5. Folders
List Folders
m365 spo folder list --webUrl "SITE_URL" --parentFolderUrl "Shared Documents" -o json \
--query '[].{name:Name, url:ServerRelativeUrl, items:ItemCount}'
m365 spo folder list --webUrl "SITE_URL" --parentFolderUrl "Shared Documents" --recursive -o json \
--query '[].{name:Name, path:ServerRelativeUrl}'
Create Folder
m365 spo folder add --webUrl "SITE_URL" --parentFolderUrl "Shared Documents" --name "New Folder" -o json
m365 spo folder add --webUrl "SITE_URL" --parentFolderUrl "Shared Documents" \
--name "Projects/2024/Q1" --ensureParentFolders true -o json
Copy / Move Folder
m365 spo folder copy --webUrl "SITE_URL" \
--sourceUrl "Shared Documents/Project-A" \
--targetUrl "/sites/archive/Shared Documents" -o json
m365 spo folder move --webUrl "SITE_URL" \
--sourceUrl "Shared Documents/Old-Folder" \
--targetUrl "/sites/project/Shared Documents/Archive" -o json
Delete Folder
m365 spo folder remove --webUrl "SITE_URL" --url "Shared Documents/Unwanted" --force
6. Permissions
List Site Users
m365 spo user list --webUrl "SITE_URL" -o json \
--query '[].{id:Id, name:Title, email:Email, login:LoginName}'
List Site Groups
m365 spo group list --webUrl "SITE_URL" -o json \
--query '[].{id:Id, name:Title, owner:OwnerTitle}'
m365 spo group list --webUrl "SITE_URL" --associatedGroupsOnly -o json
Get Group Members
m365 spo group member list --webUrl "SITE_URL" --groupId GROUP_ID -o json \
--query '[].{id:Id, name:Title, email:Email}'
m365 spo group member list --webUrl "SITE_URL" --groupName "Project Members" -o json
Add User to Group
m365 spo group member add --webUrl "SITE_URL" --groupName "Project Members" \
--userNames "user@contoso.com"
m365 spo group member add --webUrl "SITE_URL" --groupName "Project Members" \
--userNames "user1@contoso.com,user2@contoso.com"
Remove User from Group
m365 spo group member remove --webUrl "SITE_URL" --groupId GROUP_ID \
--userName "user@contoso.com" --force
File/Folder Sharing Links
m365 spo file sharinglink list --webUrl "SITE_URL" --fileUrl "Shared Documents/report.pdf" -o json \
--query '[].{id:id, type:link.type, scope:link.scope, url:link.webUrl}'
m365 spo file sharinglink add --webUrl "SITE_URL" --fileUrl "Shared Documents/report.pdf" \
--type view --scope organization -o json
m365 spo file sharinglink remove --webUrl "SITE_URL" --fileUrl "Shared Documents/report.pdf" \
--id "LINK_ID" --force
References
| File | Khi nào đọc |
|---|
references/advanced-commands.md | Page, Search, Content Type, Hub Site, Site Design, Tenant Admin |
../m365-shared/SKILL.md | Output format, JMESPath, error handling |
../m365-shared/references/authentication.md | Auth methods chi tiết |