Skip to main content

Cleanup completed Microsoft To Do tasks

Author: Garry Trinder

Microsoft To Do is my task management tool of choice, I use it for tracking everything I do, which means I generate and complete a lot of tasks during a working week.

This script iterates across all of the task lists and removes the tasks that have been marked as complete.

Write-Output "Getting Microsoft To Do task lists ..."
$lists = m365 todo list list -o json | ConvertFrom-Json

Write-Output "Iterating Microsoft To Do task lists ..."
$lists | ForEach-Object {
$listId = $_.Id

Write-Output "Getting completed tasks from '$($_.displayName)' task list ..."
$tasks = m365 todo task list --listId $listId -o json --query '[?status==`completed`]' | ConvertFrom-Json
Write-Output "$($tasks.Count) completed tasks found ..."

$tasks | ForEach-Object {
Write-Output "Removing '$($_.Title)' task ..."
m365 todo task remove --listId $listId --id $_.Id --force
}
}

Write-Output "Done"
CTRL + M