Using Update-MgPlannerTask in Graph PowerShell

The Update-MgPlannerTask cmdlet is part of the Microsoft Graph PowerShell module, which allows administrators to manage and automate tasks within Microsoft Planner. This cmdlet is essential for updating Planner tasks programmatically, making it a valuable tool for IT professionals and developers working with task management in Microsoft 365.


Cmdlet Syntax

Update-MgPlannerTask -PlannerTaskId <String> -BodyParameter <IMicrosoftGraphPlannerTask> [-IfMatch <String>] [<CommonParameters>]

Parameters:

  • -PlannerTaskId: Specifies the ID of the Planner task to update. This is a required parameter.
  • -BodyParameter: Specifies the properties of the task to update. This parameter takes a hashtable or JSON object with the properties to be updated. This is a required parameter.
  • -IfMatch: Specifies the ETag value used for concurrency control. This parameter is optional but recommended to avoid conflicts.
  • <CommonParameters>: Supports standard PowerShell common parameters.

Usage Examples

Example 1: Update Task Assignments and Categories

# Load the Microsoft Graph Planner module
Import-Module Microsoft.Graph.Planner

# Define the parameters to update the task
$params = @{
    assignments = @{
        "fbab97d0-4932-4511-b675-204639209557" = @{
            "@odata.type" = "#microsoft.graph.plannerAssignment"
            orderHint = "N9917 U2883!"
        }
    }
    appliedCategories = @{
        category3 = $true
        category4 = $false
    }
}

# Update the Planner task
Update-MgPlannerTask -PlannerTaskId $plannerTaskId -BodyParameter $params -IfMatch W/'"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBAWCc="'

In this example, the task's assignments and categories are updated using the specified parameters. The -IfMatch parameter ensures that the update is only applied if the task has not been modified since the ETag value was retrieved.

Example 2: Update Task Details

$params = @{
    title = "Updated Task Title"
    dueDateTime = "2024-07-15T00:00:00Z"
}

Update-MgPlannerTask -PlannerTaskId $plannerTaskId -BodyParameter $params -IfMatch W/'"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBAWCc="'

This example updates the task title and due date. The -IfMatch parameter helps to ensure that no concurrent modifications interfere with this update.


Cmdlet Tips

  • Use ETag for Concurrency Control: The -IfMatch parameter is useful for ensuring that the task is not updated by another process between the time you retrieve the task and the time you update it. Always use the ETag value for concurrency control.
  • JSON Formatting: Ensure that the -BodyParameter is correctly formatted as a hashtable or JSON object. Improper formatting can lead to errors.
  • Testing in a Safe Environment: Before applying changes in a production environment, test your scripts in a safe environment to prevent unintended modifications.

Possible Errors & Solutions

Error: Invoke-MgGraphRequest : The remote server returned an error: (412) Precondition Failed.

Cause: This error occurs when the ETag value does not match the current state of the resource.

Solution: Retrieve the current ETag value of the task and use it with the -IfMatch parameter.

Error: Update-MgPlannerTask : Resource not found for the segment 'plannerTaskId'.

Cause: This error occurs if the provided task ID is incorrect or does not exist.

Solution: Verify the task ID and ensure it exists in the Planner.

Error: Invalid JSON format for -BodyParameter.

Cause: This error occurs if the -BodyParameter is not correctly formatted as JSON or a hashtable.

Solution: Double-check the formatting of the -BodyParameter and ensure it adheres to the correct structure.


Conclusion

The Update-MgPlannerTask cmdlet is a powerful tool for managing tasks in Microsoft Planner programmatically. By understanding its syntax, usage, and common errors, you can effectively update tasks and streamline your task management processes. Always remember to use the -IfMatch parameter to prevent concurrency issues and ensure your updates are applied safely and accurately.

By leveraging the examples and tips provided in this guide, you can confidently incorporate Update-MgPlannerTask into your Microsoft Graph PowerShell scripts to enhance productivity and automate task management within your organization.


Related Articles:

Using Get-MgDirectoryRole in Graph PowerShell
Using Get-MgUserLicenseDetail in Graph PowerShell
Using Find-GraphMgCommand in Graph PowerShell
Connect to Microsoft 365 Using PowerShell
How to Create Bulk Users in Office 365 Using Graph PowerShell?
Create Microsoft 365 Group Using Microsoft Graph PowerShell
Block Microsoft 365 User Using Microsoft Graph PowerShell
Assign Microsoft 365 License Using Graph PowerShell
Microsoft 365 User Management Using Graph PowerShell
Checking Group Membership in Microsoft 365
Bulk Assign Microsoft 365 License
Find Inactive Users in Microsoft 365
Using Powershell Graph Search Query
Using Powershell Graph Filter Query
Using Where-Object In Graph PowerShell
Using Expand Property In Graph PowerShell
Using Select Object In Graph PowerShell
Using -Contains Operator In Graph PowerShell
Add User to Multiple Microsoft 365 Groups Using Graph PowerShell
Get Microsoft 365 User Location Using Graph PowerShell
Import Microsoft 365 Groups from CSV File Using Graph PowerShell
Microsoft 365 Group User Import Using Graph PowerShell

© m365corner.com. All Rights Reserved. Design by HTML Codex