Using Update-MgUserTodoListTask in Graph PowerShell

Managing tasks efficiently is key to staying organized, and Microsoft Graph PowerShell provides a powerful cmdlet, Update-MgUserTodoListTask, for updating tasks in a user's To-Do list. This cmdlet allows you to modify task details, such as titles, due dates, and priority, either for individual tasks or in bulk. In this article, we will cover the syntax, usage examples, cmdlet tips, potential errors with solutions, use cases, and a conclusion.

Cmdlet Syntax

Update-MgUserTodoListTask -UserId <String> -TodoTaskListId <String> -TodoTaskId <String> -BodyParameter <Hashtable>

Required Parameters:

  • -UserId: The unique identifier or UPN of the user.
  • -TodoTaskListId: The ID of the task list containing the task to update.
  • -TodoTaskId: The ID of the specific task to update.
  • -BodyParameter: A hashtable defining the properties to update, such as Title, DueDateTime, or Priority.

Usage Examples

Example 1: Update a Single Task

Modify the due date and title of a specific task.

$params = @{
    Title = "Updated Task Title"
    DueDateTime = @{
        DateTime = "2024-11-15T17:00:00Z"
        TimeZone = "UTC"
    }
}
Update-MgUserTodoListTask -UserId "user@example.com" -TodoTaskListId "A1B2C3" -TodoTaskId "D4E5F6" -BodyParameter $params

Example 2: Update Multiple Tasks

Loop through multiple tasks in the same To-Do list to update their priority.

$tasks = Get-MgUserTodoListTask -UserId "user@example.com" -TodoTaskListId "A1B2C3"
foreach ($task in $tasks) {
    $params = @{
        Priority = "high"
    }
    Update-MgUserTodoListTask -UserId "user@example.com" -TodoTaskListId "A1B2C3" -TodoTaskId $task.Id -BodyParameter $params
}

Example 3: Bulk Update via CSV

Create a CSV file (e.g., tasks.csv) with the following format:

UserId,TodoTaskListId,TodoTaskId,Title,DueDateTime
user@example.com,A1B2C3,D4E5F6,"Task 1 Updated","2024-11-20T12:00:00Z"
user@example.com,A1B2C3,G7H8I9,"Task 2 Updated","2024-11-21T15:00:00Z"

Then, use the following script:

$csv = Import-Csv "tasks.csv"
foreach ($row in $csv) {
    $params = @{
        Title = $row.Title
        DueDateTime = @{
            DateTime = $row.DueDateTime
            TimeZone = "UTC"
        }
    }
    Update-MgUserTodoListTask -UserId $row.UserId -TodoTaskListId $row.TodoTaskListId -TodoTaskId $row.TodoTaskId -BodyParameter $params
}

Cmdlet Tips

  • Retrieve Task IDs: Use Get-MgUserTodoList and Get-MgUserTodoListTask to retrieve task list and task IDs.
  • Simulate with -WhatIf: Use the -WhatIf parameter to preview changes without execution.
  • Time Zones: Always specify the TimeZone in DueDateTime to avoid scheduling issues.

Possible Errors & Solutions

Error Cause Solution
Invalid Task IDs The provided TodoTaskListId or TodoTaskId does not exist. Retrieve valid IDs using Get-MgUserTodoList and Get-MgUserTodoListTask.
Bad Request Malformed or missing BodyParameter properties. Ensure the BodyParameter adheres to the expected schema.
Unauthorized Insufficient permissions. Grant Tasks.ReadWrite permissions to the app or token.

Use Cases

  • Automating Task Updates: Automate updates to task properties like priority, due dates, or titles.
  • Error Correction: Fix mismatched task details across multiple users using bulk updates.
  • Standardization: Ensure task naming conventions or deadlines are standardized across teams.

Conclusion

The Update-MgUserTodoListTask cmdlet is a versatile tool for modifying tasks in Microsoft To-Do lists. By following the examples and tips provided, administrators can effectively update single or multiple tasks with minimal effort. Whether you're managing tasks for an individual or an entire team, this cmdlet can save you time and improve productivity.

Leverage this guide to streamline task management and ensure efficient handling of task updates across your organization.

© M365Corner. All Rights Reserved. Design by HTML Codex.