Public/Get-DunePatchingWindowAssignment.ps1
|
<# .SYNOPSIS Retrieve assignments of patching windows. .DESCRIPTION Gets patching window assignments. Supports parameter sets for `Id`, `ResourceGroup`, and `PatchingWindow` and can return raw API objects using `-Raw`. .PARAMETER Id The GUID of a patching window assignment. Use the `Id` parameter set to retrieve a specific assignment. .PARAMETER ResourceGroup A `DuneResourceGroup` object; returns assignments scoped to the provided resource group (pipeline input supported). .PARAMETER PatchingWindow A `DunePatchingWindow` object or GUID used to filter assignments (pipeline input supported). .PARAMETER Raw If set, returns raw API objects instead of `DunePatchingWindowAssignment` objects. .EXAMPLE PS> Get-DunePatchingWindowAssignment Returns all patching window assignments. .EXAMPLE PS> Get-DunePatchingWindowAssignment -Id 3d8f6b5a-... Returns the assignment with the specified `Id`. .EXAMPLE PS> Get-DuneResourceGroup -Name "rg-prod" | Get-DunePatchingWindowAssignment Pipeline example using the `ResourceGroup` parameter set. #> function Get-DunePatchingWindowAssignment { [CmdletBinding(DefaultParameterSetName = "Default")] param ( [Parameter(ParameterSetName = "Id")] [guid]$Id, [Parameter(ParameterSetName = "ResourceGroup", ValueFromPipeline)] [DuneResourceGroup]$ResourceGroup, [Parameter(ParameterSetName = "PatchingWindow")] [guid]$ResourceGroupId, [Parameter(ParameterSetName = "PatchingWindow", ValueFromPipeline)] [DunePatchingWindow]$PatchingWindow, [Parameter(ParameterSetName = "ResourceGroup")] [guid]$PatchingWindowId, [Parameter()] [switch]$Raw ) begin { Write-Debug "$($MyInvocation.MyCommand)|begin" $ReturnObjects = @() $ProcessedUrls = @() $BaseUri = "patching/windows/assignments" $Method = "GET" } process { Write-Debug "$($MyInvocation.MyCommand)|process|$($PSCmdlet.ParameterSetName)" # Build Uri switch ($PSCmdlet.ParameterSetName) { 'Id' { $Uri = '{0}?Id={1}' -f $BaseUri, $Id } 'ResourceGroup' { $Uri = '{0}?ResourceGroupId={1}' -f $BaseUri, $ResourceGroup.Id if ($PatchingWindowId) { $Uri, "PatchingWindowId=$PatchingWindowId" -join "&" } } 'PatchingWindow' { $Uri = '{0}?PatchingWindowId={1}' -f $BaseUri, $PatchingWindow.id if ($ResourceGroupId) { $Uri, "ResourceGroupId=$ResourceGroupId" -join "&" } } Default { $Uri = $BaseUri } } # ApiCall Cache if ($ProcessedUrls -notcontains $Uri) { try { # ApiCall and Object conversion $Response = Invoke-DuneApiRequest -Uri $Uri -Method $Method $ProcessedUrls += $Uri $Results = if ($Response.Content) { $Response.Content | ConvertFrom-Json } $ReturnObjects += $Results.items | ForEach-Object { if ($Raw) { $_ } else { ConvertTo-DuneClassObject -Class DunePatchingWindowAssignment -InputObject $_ } } } catch { throw $_ } } else { Write-Debug "$($MyInvocation.MyCommand)|process|ApiCall Cache hit: DuneApiRequest for $Uri already invoked" } } end { Write-Debug "$($MyInvocation.MyCommand)|end" return $ReturnObjects } } |