| name | m365-onedrive |
| description | Trigger this skill for any action on the user's personal OneDrive — their own private Microsoft 365 cloud storage ("My files"), referred to as "onedrive", "onedrive cá nhân", "onedrive của tôi", "trên onedrive", "lên onedrive". Fire the moment a request names OneDrive and wants to do something with files or folders there: liệt kê/xem (list/browse), tạo/đổi tên/di chuyển/sao chép/xóa (create/rename/move/copy/delete) files & folders, tải lên (upload local files), tải về (download), tạo/gỡ link chia sẻ (share links), xem dung lượng trống/quota (free space), khôi phục bản cũ (restore an earlier version). Casual, terse, or unaccented phrasing still counts — just proceed, don't ask which storage they mean, and treat it as cloud storage rather than a local file task. This is INDIVIDUAL cloud storage, NOT a team site: send a team/group's "Shared Documents" or Files-tab documents to m365-sharepoint, Teams chat/channels to m365-teams, and Google Drive to gws-drive.
|
| allowed-tools | ["Bash","Read"] |
m365-onedrive — Personal OneDrive 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
- OneDrive uses
spo file/folder commands with OneDrive URL pattern: https://{tenant}-my.sharepoint.com/personal/{user_encoded}
- Always resolve OneDrive URL first before any file operation
- Output: always
-o json with --query
- Default document library folder:
Documents
1. Discover — Find OneDrive URL
Auto-resolve Current User's OneDrive URL (non-admin)
KHÔNG construct URL bằng tay: tên tenant SharePoint thường KHÁC domain email (vd @miichisoft.com → host miichisoftjsc-my.sharepoint.com), nên ghép chuỗi bằng sed sẽ ra sai host. Hỏi thẳng Microsoft Graph để lấy webUrl chính xác:
m365 request --url 'https://graph.microsoft.com/v1.0/me/drive?$select=webUrl' -o json --query 'webUrl'
ONEDRIVE_URL=$(m365 request --url 'https://graph.microsoft.com/v1.0/me/drive?$select=webUrl' -o json --query 'webUrl' | tr -d '"' | sed 's#/Documents$##')
Check Storage Usage (non-admin)
m365 request --url 'https://graph.microsoft.com/v1.0/me/drive?$select=quota' -o json \
--query 'quota.{usedBytes:used, totalBytes:total, remainingBytes:remaining}'
m365 onedrive list là lệnh admin (trả 403 với user thường). Đường Graph me/drive ở trên hoạt động với mọi user.
2. File Operations
All file commands use spo file with the OneDrive web URL.
List Files
m365 spo file list --webUrl "ONEDRIVE_URL" --folderUrl "Documents" -o json \
--query '[].{name:Name, size:Length, modified:TimeLastModified, url:ServerRelativeUrl}'
m365 spo file list --webUrl "ONEDRIVE_URL" --folderUrl "Documents/Projects" -o json \
--query '[].{name:Name, size:Length}'
m365 spo file list --webUrl "ONEDRIVE_URL" --folderUrl "Documents" --recursive -o json \
--query '[].{name:Name, path:ServerRelativeUrl, size:Length}'
m365 spo file list --webUrl "ONEDRIVE_URL" --folderUrl "Documents" \
--filter "substringof('report',Name)" -o json --query '[].{name:Name}'
Upload File
spo file add sắp đổi mặc định --overwrite thành false — luôn set rõ ràng để tránh cảnh báo và hành vi bất ngờ.
m365 spo file add --webUrl "ONEDRIVE_URL" --folder "Documents" --path "/local/path/file.pdf" --overwrite true -o json
m365 spo file add --webUrl "ONEDRIVE_URL" --folder "Documents/Reports" --path "/local/path/report.xlsx" --overwrite true -o json
m365 spo file add --webUrl "ONEDRIVE_URL" --folder "Documents" --path "/local/path/file.pdf" \
--fileName "quarterly-report.pdf" --overwrite true -o json
Download File
m365 spo file get --webUrl "ONEDRIVE_URL" --url "Documents/report.pdf" --asFile --path "/local/download/report.pdf"
Copy File
m365 spo file copy --webUrl "ONEDRIVE_URL" \
--sourceUrl "Documents/original.pdf" \
--targetUrl "/personal/user_contoso_com/Documents/Archive" -o json
m365 spo file copy --webUrl "ONEDRIVE_URL" \
--sourceUrl "Documents/original.pdf" \
--targetUrl "/personal/user_contoso_com/Documents/Archive" \
--newName "backup-original" -o json
Move File
m365 spo file move --webUrl "ONEDRIVE_URL" \
--sourceUrl "Documents/old-folder/file.pdf" \
--targetUrl "/personal/user_contoso_com/Documents/new-folder" -o json
Delete File
m365 spo file remove --webUrl "ONEDRIVE_URL" --url "Documents/unwanted.pdf" --force
3. Folder Operations
List Folders
m365 spo folder list --webUrl "ONEDRIVE_URL" --parentFolderUrl "Documents" -o json \
--query '[].{name:Name, url:ServerRelativeUrl, items:ItemCount}'
m365 spo folder list --webUrl "ONEDRIVE_URL" --parentFolderUrl "Documents" --recursive -o json \
--query '[].{name:Name, path:ServerRelativeUrl}'
Create Folder
m365 spo folder add --webUrl "ONEDRIVE_URL" --parentFolderUrl "Documents" --name "New Folder" -o json
m365 spo folder add --webUrl "ONEDRIVE_URL" --parentFolderUrl "Documents" \
--name "Projects/2024/Q1" --ensureParentFolders true -o json
Copy Folder
m365 spo folder copy --webUrl "ONEDRIVE_URL" \
--sourceUrl "Documents/Project-A" \
--targetUrl "/personal/user_contoso_com/Documents/Archive" -o json
Move Folder
m365 spo folder move --webUrl "ONEDRIVE_URL" \
--sourceUrl "Documents/Old-Folder" \
--targetUrl "/personal/user_contoso_com/Documents/Archive" -o json
Delete Folder
m365 spo folder remove --webUrl "ONEDRIVE_URL" --url "Documents/Unwanted-Folder" --force
4. Sharing
List Sharing Links
m365 spo file sharinglink list --webUrl "ONEDRIVE_URL" --fileUrl "Documents/shared-report.pdf" -o json \
--query '[].{id:id, type:link.type, scope:link.scope, url:link.webUrl}'
m365 spo file sharinglink list --webUrl "ONEDRIVE_URL" --fileUrl "Documents/report.pdf" \
--scope anonymous -o json
Create Sharing Link
m365 spo file sharinglink add --webUrl "ONEDRIVE_URL" --fileUrl "Documents/report.pdf" \
--type view --scope organization -o json
m365 spo file sharinglink add --webUrl "ONEDRIVE_URL" --fileUrl "Documents/report.pdf" \
--type edit --scope organization -o json
m365 spo file sharinglink add --webUrl "ONEDRIVE_URL" --fileUrl "Documents/report.pdf" \
--type view --scope anonymous --expirationDateTime "2025-12-31T23:59:59Z" -o json
Remove Sharing Link
m365 spo file sharinglink remove --webUrl "ONEDRIVE_URL" --fileUrl "Documents/report.pdf" \
--id "LINK_ID" --force
5. Versions
List File Versions
m365 spo file version list --webUrl "ONEDRIVE_URL" --fileUrl "Documents/report.xlsx" -o json \
--query '[].{id:ID, version:VersionLabel, size:Size, modified:Created, modifiedBy:CreatedBy}'
Get Specific Version
m365 spo file version get --webUrl "ONEDRIVE_URL" --fileUrl "Documents/report.xlsx" \
--label "1.0" -o json
Restore Version
m365 spo file version restore --webUrl "ONEDRIVE_URL" --fileUrl "Documents/report.xlsx" \
--label "1.0" --force
Workflow: Resolve URL + Upload
Complete workflow for uploading a file to OneDrive:
ONEDRIVE_URL=$(m365 request --url 'https://graph.microsoft.com/v1.0/me/drive?$select=webUrl' -o json --query 'webUrl' | tr -d '"' | sed 's#/Documents$##')
m365 spo file add --webUrl "$ONEDRIVE_URL" --folder "Documents" --path "/local/file.pdf" --overwrite true -o json
References
| File | Khi nào đọc |
|---|
../m365-shared/SKILL.md | Output format, JMESPath, error handling |
../m365-shared/references/authentication.md | Auth methods chi tiết |
../m365-sharepoint/SKILL.md | Khi cần thao tác file trên SharePoint site (không phải OneDrive cá nhân) |