Public/New-DunePatchingWindow.ps1

<#
.SYNOPSIS
Create a new patching window.

.DESCRIPTION
Creates a patching window specifying monthly occurrence, day of week, time of day and optional duration. Observes `ShouldProcess`.

.PARAMETER MonthlyOccurence
The monthly occurrence value (from `MonthlyDayOccurence` enum). Mandatory.

.PARAMETER DayOfWeek
The day of week for the window (from `dayofweek` enum). Mandatory.

.PARAMETER TimeOfDay
Time of day string for when the window starts. Mandatory.

.PARAMETER Duration
Optional `TimeSpan` for window duration.

.EXAMPLE
PS> New-DunePatchingWindow -MonthlyOccurence First -DayOfWeek Monday -TimeOfDay "02:00"
Creates a patching window occurring on the first Monday at 02:00.
#>

function New-DunePatchingWindow {
    [CmdletBinding(
        SupportsShouldProcess,
        ConfirmImpact = 'None'
    )]
    param (
        [Parameter(Mandatory)]
        [MonthlyDayOccurence]$MonthlyOccurence,

        [Parameter(Mandatory)]
        [dayofweek]$DayOfWeek,

        [Parameter(Mandatory)]
        [String]$TimeOfDay, #inPS7 use System.TimeOnly

        [Parameter()]
        [timespan]$Duration
    )

    begin {}

    process {
        Write-Debug "$($MyInvocation.MyCommand)|process"
        $Body = @{
            MonthlyOccurence = $MonthlyOccurence.ToString()
            DayOfWeek        = $DayOfWeek.ToString()
            TimeOfDay        = $TimeOfDay
            Duration         = $Duration
        }
        if ($PSCmdlet.ShouldProcess($($Body | ConvertTo-Json -Depth 16 -Compress))) {
            $Return = Invoke-DuneApiRequest -Uri "patching/windows" -Method POST -Body $Body
            $ReturnObject = if ($Return.Content) { $Return.Content | ConvertFrom-Json | ConvertTo-DuneClassObject -Class DunePatchingWindow }
            return $ReturnObject
        }
    }

    end {}
}