Cleanup completed Microsoft To Do tasks
Summary
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.
Warning
Please be aware this script contains a command that will remove or delete an artifact, ensure you test and understand the implications of running the script.
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 --confirm
}
}
Write-Output "Done"
Check out the CLI for Microsoft 365 to learn more at: https://aka.ms/cli-m365
Source Credit
Sample first appeared on Cleanup completed Microsoft To Do tasks | CLI for Microsoft 365
Contributors
Author(s) |
---|
Garry Trinder |
Disclaimer
THESE SAMPLES ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.