Table of Contents
Retention Policies Can Remove Old Planner Tasks – So Can PowerShell
Microsoft Purview is adding support for retention policies for Planner tasks and the functionality should turn up in tenants during August 2026, so why write about how to remove old Planner tasks with PowerShell? My real reason is that writing such a script has been on my to-do list for the last three years, but something always seemed to interfere and stopped me writing the code. A better reason is that exercises like this help administrators understand how Microsoft 365 works behind the scenes. At least, that’s what I keep on telling myself.
Writing the script wasn’t difficult, especially after writing the code to report obsolete tasks. A couple of potential gotchas were encountered along the way, but nothing too difficult. Let’s get into what the script code.
Finding Old Planner Tasks
The basic idea is similar to the approach used to analyze obsolete tasks. The way to find plans is via Microsoft 365 groups. This is particularly true when looking for old data because user (personal) plans have only been available for a couple of years. The first step is therefore to find Microsoft 365 groups before checking each group for any plans that might be group resources.
Once the script finds a plan, it can fetch and check tasks. As explained in my previous article, the tasks endpoint ignores Graph filters, so it’s necessary to retrieve every task in each plan and then use a client-side filter to find tasks older than a threshold date. Fortunately, most plans have relatively small numbers of tasks. The largest plan in my tenant has just over 8,500 tasks because the tasks are notifications synchronized from the Message Center. Removing old tasks from this plan helped client performance significantly, especially when fetching tasks with the mobile Planner client.
Deleting Old Planner Tasks
After identifying old tasks, the script runs the Remove-MgPlannerTask cmdlet. The slight complication here is that the cmdlet requires the IfMatch parameter to check a tag value found in the additionalProperties property. Planner is the only workload I know of whose Microsoft Graph PowerShell SDK cmdlets have such a requirement. It seems strange that the cmdlet can’t hide the complication better. In any case, the code to remove a task is:
Remove-MgPlannerTask -PlannerTaskId $Task.Id -IfMatch $Task.additionalProperties.'@odata.etag' -ErrorAction Stop
The other thing to remember is that flooding the service with a rapid bunch of delete operations is likely to result in throttling. I therefore included a rudimentary step to avoid throttling by pausing for a second after processing deleted tasks for a plan. Basic as the step is, it seems to work.

After processing all plans, the script generates some statistics, creates a report file, and emails the report to a designated recipient (Figure 2).

Script Implementation
Scripts that need to process tenant-wide data require Microsoft Graph application permissions. Either app-only authentication or a managed identity running in an Azure Automation runbook will work well. The required permissions are GroupMember.Read.All (read basic group information), Tasks.ReadWrite.All (remove tasks from plans), and Mail.Send (send the report email). Consider using RBAC for Applications to restrict the script’s ability to access Exchange Online mailboxes.
Writing the script to clean up obsolete tasks scratched an itch for me. You can download the code from the Microsoft 365 for IT Pros GitHub repository. Have fun!
Microsoft 365 for IT Pros continues to earn 5-star reviews from readers—and for good reason. If you manage a Microsoft 365 tenant, you’ll benefit from practical, real-world guidance written by experts who work with the platform every day. The subscription includes extensive coverage of Microsoft 365 administration, security, compliance, and governance, plus a 450-page book dedicated to automating Microsoft 365 with PowerShell.
Microsoft 365 for IT Pros is a trusted source of technical insight that helps tenant administrators stay informed and productive. We update the content every month to reflect changes across Microsoft 365, and monthly update #133 is available now. Get your copy from Gumroad.com and stay up to date with the information that matters most for keeping your tenant secure, compliant, and running efficiently.