Using New-MgUserTodoListTask in Graph PowerShell

The New-MgUserTodoListTask cmdlet in Microsoft Graph PowerShell is a powerful tool for creating tasks in a specific To-Do list for users in your organization. This cmdlet enables IT administrators to streamline task management operations by automating the creation of tasks for individuals or in bulk. Whether you’re assigning individual tasks, multiple tasks, or creating tasks from a CSV file, this guide covers it all.

Cmdlet Syntax

New-MgUserTodoListTask -UserId <String> -TodoTaskListId <String> -BodyParameter <PSObject>

Required Parameters:

  • -UserId: The ID or UPN (User Principal Name) of the user for whom the task is being created.
  • -TodoTaskListId: The ID of the To-Do list where the task will be created.
  • -BodyParameter: A hashtable containing the task properties such as title, due date, and importance.

Usage Examples

Example 1: Create a Single Task

Create a task with specific details such as a title, due date, and priority.

$TaskDetails = @{
    title = "Prepare Quarterly Report"
    dueDateTime = @{ dateTime = "2024-11-15T17:00:00"; timeZone = "UTC" }
    importance = "high"
}
New-MgUserTodoListTask -UserId "john.doe@contoso.com" -TodoTaskListId "A1B2C3D4" -BodyParameter $TaskDetails

Example 2: Create Multiple Tasks

Create multiple tasks for a user by iterating through a list of task details.

$Tasks = @(
    @{ title = "Complete Budget Analysis"; dueDateTime = @{ dateTime = "2024-11-18T17:00:00"; timeZone = "UTC" }; importance = "normal" },
    @{ title = "Team Meeting Preparation"; dueDateTime = @{ dateTime = "2024-11-20T10:00:00"; timeZone = "UTC" }; importance = "low" }
)
foreach ($Task in $Tasks) {
    New-MgUserTodoListTask -UserId "john.doe@contoso.com" -TodoTaskListId "A1B2C3D4" -BodyParameter $Task
}

Example 3: Bulk Create Tasks via CSV

Use a CSV file to create tasks for multiple users. The CSV should contain columns for UserId, TodoTaskListId, Title, DueDateTime, and Importance.

$Tasks = Import-Csv "Tasks.csv"
foreach ($Task in $Tasks) {
    $TaskDetails = @{
        title = $Task.Title
        dueDateTime = @{ dateTime = $Task.DueDateTime; timeZone = "UTC" }
        importance = $Task.Importance
    }
    New-MgUserTodoListTask -UserId $Task.UserId -TodoTaskListId $Task.TodoTaskListId -BodyParameter $TaskDetails
}

Cmdlet Tips

  • Time Zone Awareness: Ensure the dueDateTime field includes a valid time zone to avoid scheduling errors.
  • Validation: Always validate the UserId and TodoTaskListId before executing the cmdlet to prevent errors.
  • CSV Headers: Use consistent headers in your CSV files to avoid parsing issues.

Possible Errors & Solutions

Error Cause Solution
InvalidAuthenticationToken The user account lacks proper permissions to execute the cmdlet. Ensure the account has the Tasks.ReadWrite permission in Microsoft Graph.
ResourceNotFound The TodoTaskListId provided does not exist or is incorrect. Use Get-MgUserTodoList to retrieve the correct list ID.
BadRequest Incorrect or missing properties in the -BodyParameter. Ensure required properties such as title and dueDateTime are included.

Conclusion

The New-MgUserTodoListTask cmdlet is an invaluable tool for task automation in Microsoft 365 environments. By leveraging its capabilities, administrators can efficiently manage user workloads, ensure deadlines are met, and improve task assignment workflows. Whether you're creating a single task or handling bulk assignments via CSV, this cmdlet simplifies the process with precision and flexibility.

Suggested Reading

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