Using New-MgPlannerPlan in Graph PowerShell

The New-MgPlannerPlan cmdlet in Microsoft Graph PowerShell is a powerful tool for creating new plans in Microsoft Planner. This cmdlet allows you to automate the creation of plans (either associated with specific Microsoft 365 groups or standalone plans). In this article, we will explore the syntax, usage examples, tips, use cases, possible errors, and enhancements to help you effectively utilize this cmdlet.


Cmdlet Syntax

New-MgPlannerPlan -BodyParameter <Object>

The -BodyParameter property is mandatory and takes a hashtable containing the plan details.


Usage Examples

Create a Plan Associated with a Group

$params = @{
    title = "Project Launch Plan"
    container = @{
        url = "https://graph.microsoft.com/v1.0/groups/ebf3b108-5234-4e22-b93d-656d7dae5874"
    }
}

New-MgPlannerPlan -BodyParameter $params

Note: Use New-MgGroup cmdlet to get the required Group ID.


Create a Plan Not Associated with Any Group

$params = @{
    title = "Personal Development Plan"
    container = @{
        url = "https://graph.microsoft.com/v1.0/users/your-user-id"
    }
}
                            
New-MgPlannerPlan -BodyParameter $params

Note: Use New-MgUser cmdlet to get the required User ID. This user becomes the plan owner.

Create Multiple Plans Using a Script

$plans = @(
    @{
        title = "Marketing Campaign Plan"
        container = @{
            url = "https://graph.microsoft.com/v1.0/groups/group-id-1"
        }
    }
    @{
        title = "Product Launch Plan"
        container = @{
            url = "https://graph.microsoft.com/v1.0/groups/group-id-2"
        }
    }
)

foreach ($plan in $plans) {
    New-MgPlannerPlan -BodyParameter $plan
}

Create Multiple Plans Using a CSV File

$csv = Import-Csv -Path "plans.csv"

foreach ($row in $csv) {
    $params = @{
        title = $row.title
        container = @{
            url = $row.url
        }
    }
    New-MgPlannerPlan -BodyParameter $params
}

plans.csv example:

title,url
"Sales Strategy Plan","https://graph.microsoft.com/v1.0/groups/group-id-3"
"Customer Support Plan","https://graph.microsoft.com/v1.0/groups/group-id-4"

Cmdlet Tips

  • Container URL: The container property must be specified within the -BodyParameter hashtable. It takes a URL that includes the group or user ID associated with the plan.
  • Permissions: Ensure you have the necessary permissions to create plans in the specified groups or for the user.
  • Error Handling: Always include error handling in your scripts to manage possible issues during plan creation.

Use Cases

  • Project Management: Automate the creation of project plans for various teams within your organization.
  • Personal Task Planning: Create personal development or task plans not tied to any specific group.
  • Departmental Coordination: Set up plans for different departments using a predefined structure, improving coordination and tracking.

Possible Errors & Enhancements

Error: Insufficient Permissions

Cause: The account used to run the cmdlet does not have the required permissions.

Solution: Ensure the account has Group.ReadWrite.All Graph API permission.

# Example of handling insufficient permissions error
try {
    New-MgPlannerPlan -BodyParameter $params
} catch {
    Write-Host "Error: Insufficient Permissions. Ensure the account has the necessary permissions."
}

Error: Invalid Container URL

Cause: The URL provided in the container property is incorrect.

Solution: Verify the URL and ensure it follows the correct format with the group or user ID.

$params = @{
    title = "Valid Plan"
    container = @{
        url = "https://graph.microsoft.com/v1.0/groups/valid-group-id"
    }
}

try {
    New-MgPlannerPlan -BodyParameter $params
} catch {
    Write-Host "Error: Invalid Container URL. Verify the URL format and group/user ID."
}

Error: Missing Required Properties

Cause: The -BodyParameter hashtable does not include all required properties.

Solution: Ensure the title and container properties are included in the hashtable.

$params = @{
    # Missing required properties
}

try {
    New-MgPlannerPlan -BodyParameter $params
} catch {
    Write-Host "Error: Missing Required Properties. Ensure 'title' and 'container' are included."
}

Conclusion

The New-MgPlannerPlan cmdlet is a versatile tool for creating plans in Microsoft Planner. Whether you need to create plans associated with specific groups or standalone plans, this cmdlet provides the flexibility to automate the process efficiently. By following the usage examples, tips, and handling possible errors effectively, you can leverage the power of this cmdlet to enhance your planning and project management capabilities within Microsoft 365.

For more detailed information, refer to the official New-MgPlannerPlan documentation.


Additional Resources:

Microsoft Graph PowerShell Module Documentation
Microsoft Graph API Documentation

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