Public/Get-DunePatchingWindow.ps1
|
function Get-DunePatchingWindow { [CmdletBinding(DefaultParameterSetName = "Default")] param ( [Parameter(Position = 0)] [string]$Name, [Parameter(ParameterSetName = "Id")] [guid]$Id, [Parameter(ParameterSetName = "Deployment", ValueFromPipeline)] [DuneDeployment]$Deployment, [Parameter()] [string]$DayOfWeek, #wildcard not supported [Parameter()] [string]$MonthlyOccurence, #wildcard not supported [Parameter()] [switch]$Raw ) begin { Write-Debug "$($MyInvocation.MyCommand)|begin" $ReturnObjects = @() $ProcessedUrls = @() $BaseUri = "patching/windows" $Method = "GET" } process { Write-Debug "$($MyInvocation.MyCommand)|process|$($PSCmdlet.ParameterSetName)" if ($Deployment) { $ReturnObjects += (Get-DunePatchingWindowAssignment -Deployment $Deployment).PatchingWindow } else { # Build Uri $Uri = switch ($PSCmdlet.ParameterSetName) { 'Id' { '{0}?Id={1}' -f $BaseUri, $Id } Default { $BaseUri } } if ($Name) { $Uri = $Uri | Add-UriQueryParam "NameILike=$Name" -ConvertWildcards } if ($DayOfWeek) { $Uri = $Uri | Add-UriQueryParam "DayOfWeek=$DayOfWeek" } if ($MonthlyOccurence) { $Uri = $Uri | Add-UriQueryParam "MonthlyOccurence=$MonthlyOccurence" } # 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 DunePatchingWindow -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 } } |