Functions/Planner/New-PlannerPlan.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Function New-PlannerPlan
{
    [CmdletBinding()]
    Param(      
        [Parameter(Mandatory = $true,
                   ValueFromPipeline = $true,
                   ValueFromPipelineByPropertyName = $true)]
        [ValidateNotNullOrEmpty()]
        [string]$GroupId = @(),

        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [string]$Title
    )

    $emptyGuid = [guid]::Empty
    if ([guid]::TryParse($GroupId, [ref]$emptyGuid))
    {
        $body = (@{
            owner     = $GroupId
            title     = $Title
        }) | ConvertTo-Json

        $uri = $global:PowerGraph_BaseUrl + "planner/plans"

        Write-Verbose "Adding new planner: $Title with $body"

        $plan = Invoke-MSGraphRequest -Uri $uri -Method Post -Body $body
    }
    else
    {
        throw "Invalid Group ID - $GroupId"
    }
}