Operate the built-in Microsoft To Do app on Windows via PowerShell. Supports creating tasks, managing lists, setting reminders, and marking as complete.
Use cases
- The user says "help me add a to-do", "what should I do today", "mark task XX as complete"
- The user needs to organize a task list
- The user needs to set a reminder or due date
- Task management integrated with Outlook calendar/email
Command reference
Quick operations via the URI protocol
# 打开 To Do 应用
Start-Process "ms-todo:"
Quickly add a task (open To Do and focus on new item)
Start-Process "ms-todo://create"
Open the "My Day" viewStart-Process "ms-todo://myday"
### 通过 Microsoft Graph API(PowerShell)
```powershell
# ===== 前置:获取访问令牌 =====
# 使用设备码流登录(首次使用时执行一次)
$clientId = "YOUR_APP_CLIENT_ID" # 需在 Azure AD 注册应用
$scope = "Tasks.ReadWrite"
$body = @{
client_id = $clientId
scope = $scope
}
$deviceCode = Invoke-RestMethod -Uri "https://login.microsoftonline.com/consumers/oauth2/v2.0/devicecode" -Method POST -Body $body
Write-Output "请打开 $($deviceCode.verification_uri) 并输入代码: $($deviceCode.user_code)"
# ===== 列出所有任务列表 =====
$headers = @{ Authorization = "Bearer $token" }
$lists = Invoke-RestMethod -Uri "https://graph.microsoft.com/v1.0/me/todo/lists" -Headers $headers
$lists.value | ForEach-Object { Write-Output "$($_.id) — $($_.displayName)" }
# ===== 列出某列表中的任务 =====
$listId = "LIST_ID"
$tasks = Invoke-RestMethod -Uri "https://graph.microsoft.com/v1.0/me/todo/lists/$listId/tasks" -Headers $headers
$tasks.value | Where-Object { $_.status -ne "completed" } | ForEach-Object {
Write-Output "[ ] $($_.title) $(if($_.dueDateTime){'📅 '+$_.dueDateTime.dateTime})"
}
# ===== 创建新任务 =====
$newTask = @{
title = "完成季度报告"
dueDateTime = @{
dateTime = "2025-03-15T17:00:00"
timeZone = "Asia/Shanghai"
}
importance = "high"
body = @{
content = "包括销售数据和趋势分析"
contentType = "text"
}
} | ConvertTo-Json -Depth 3
Invoke-RestMethod -Uri "https://graph.microsoft.com/v1.0/me/todo/lists/$listId/tasks" -Headers $headers -Method POST -Body $newTask -ContentType "application/json"
# ===== 标记任务完成 =====
$taskId = "TASK_ID"
$update = @{ status = "completed" } | ConvertTo-Json
Invoke-RestMethod -Uri "https://graph.microsoft.com/v1.0/me/todo/lists/$listId/tasks/$taskId" -Headers $headers -Method PATCH -Body $update -ContentType "application/json"
Simplified approach (no API, via URI + clipboard)
# 用 URI 协议 + 剪贴板实现快速添加
$task = "完成季度报告"
Set-Clipboard -Value $task
Start-Process "ms-todo://create"
# 提示用户:已复制到剪贴板,To Do 打开后 Ctrl+V 粘贴
Output specifications
- Use checklist format for task lists:
[ ] 未完成任务/[x] 已完成任务 - Show due dates and importance markers
- Confirm the result after create/complete operations
- Prioritize display in the "My Day" view
Safety rules
- HITL confirmation is required before deleting a list
- Do not mark as complete in bulk (confirm one by one)
- Do not modify lists shared by other users