Scripts/Get-BPACalendar.ps1
function Get-BPACalendar { <# .SYNOPSIS Gets AutoMate BPA calendar events. .DESCRIPTION Get-BPACalendar gets events from the calendar. .PARAMETER StartDate The first date of events to retrieve (Default: now - must be equal or greater than the current time). .PARAMETER EndDate The last date of events to retrieve (Default: 24 hours from now). .PARAMETER Type The schedule types to retrieve: Specific - The schedule defines specific dates and times. Weekly - The schedule reoccurs on a weekly basis. Monthly - The schedule reoccurs on a monthly basis. Holidays - The schedule occurs on a holiday. Non-Interval - ??? .PARAMETER FilterSet The parameters to filter the search on. Supply hashtable(s) with the following properties: Property, Comparator, Value. Valid values for the Comparator are: =, !=, <, >, contains (default - no need to supply Comparator when using 'contains') .PARAMETER FilterSetMode If multiple filter sets are provided, FilterSetMode determines if the filter sets should be evaluated with an AND or an OR .PARAMETER SortProperty The object property to sort results on. Do not use BPAServer or TypeName, since those are custom properties added by this module, and not exposed in the API. .PARAMETER SortDescending If specified, this will sort the output on the specified SortProperty in descending order. Otherwise, ascending order is assumed. .PARAMETER BPAServer The AutoMate BPA management server. .INPUTS Calendar events related to the following objects can be retrieved by this function: Workflow Condition Folder .EXAMPLE # Get calendar events for the next 7 days Get-BPACalendar -EndDate (Get-Date).AddDays(7) .EXAMPLE # Get calendar events for workflow "My Workflow" Get-BPAWorkflow "My Workflow" | Get-BPACalendar .EXAMPLE # Get calendar events using filter sets Get-BPACalendar -FilterSet @{Property = 'ScheduleDescription'; Comparator = 'contains'; Value = 'hour(s)'} .NOTES Author(s): : David Seibel Contributor(s) : Date Created : 09/19/2016 Date Modified : 03/06/2018 .LINK https://github.com/davidseibel/PoshBPA #> [CmdletBinding(DefaultParameterSetName = "All")] [OutputType([System.Object[]])] param( [Parameter(Position = 0, ParameterSetName = "ByPipeline", ValueFromPipeline = $true)] [ValidateNotNullOrEmpty()] $InputObject, [ValidateNotNullOrEmpty()] [DateTime]$StartDate = (Get-Date), [ValidateNotNullOrEmpty()] [DateTime]$EndDate = (Get-Date).AddDays(1), [ValidateSet("Specific","Weekly","Monthly","Holidays","Non-interval")] [string]$Type, [Hashtable[]]$FilterSet, [ValidateSet("And","Or")] [string]$FilterSetMode = "And", [ValidateNotNullOrEmpty()] [string[]]$SortProperty = "NextRunTime", [switch]$SortDescending = $false, [ValidateNotNullOrEmpty()] [string]$BPAServer ) BEGIN { if ($StartDate -gt $EndDate) { throw "StartDate must be before EndDate!" } $splat = @{ RestMethod = "Get" BPAServer = $BPAServer } $result = @() } PROCESS { switch($PSCmdlet.ParameterSetName) { "All" { $splat += @{ Resource = Format-BPAUri -Path "calendar/list" -RangeStart $StartDate -RangeEnd $EndDate -FilterSet $FilterSet -FilterSetMode $FilterSetMode -CalendarType $Type -SortProperty $SortProperty -SortDescending:$SortDescending.ToBool() } $result = Invoke-BPARestMethod @splat } "ByPipeline" { foreach ($obj in $InputObject) { Write-Verbose "Processing object Name: '$($obj.Name)' Type: '$($obj.TypeName)'" $tempSplat = $splat if (-not $tempSplat.ContainsKey("BPAServer")) { $tempSplat += @{ BPAServer = $obj.BPAServer } } else { $tempSplat["BPAServer"] = $obj.BPAServer } switch ($obj.TypeName) { "Workflow" { $tempFilterSet = $FilterSet + @{Property = "WorkflowID"; Comparator = "="; Value = $obj.ID} $tempSplat += @{ Resource = Format-BPAUri -Path "calendar/list" -RangeStart $StartDate -RangeEnd $EndDate -FilterSet $tempFilterSet -FilterSetMode $FilterSetMode -CalendarType $Type -SortProperty $SortProperty -SortDescending:$SortDescending.ToBool() } $result += Invoke-BPARestMethod @tempSplat } "Condition" { $tempFilterSet = $FilterSet + @{Property = "ScheduleID"; Comparator = "="; Value = $obj.ID} $tempSplat += @{ Resource = Format-BPAUri -Path "calendar/list" -RangeStart $StartDate -RangeEnd $EndDate -FilterSet $tempFilterSet -FilterSetMode $FilterSetMode -CalendarType $Type -SortProperty $SortProperty -SortDescending:$SortDescending.ToBool() } $result += Invoke-BPARestMethod @tempSplat } "Folder" { $tempSplat += @{ Resource = Format-BPAUri -Path "calendar/list" -RangeStart $StartDate -RangeEnd $EndDate -FolderID $obj.ID -FilterSet $tempFilterSet -FilterSetMode $FilterSetMode -CalendarType $Type -SortProperty $SortProperty -SortDescending:$SortDescending.ToBool() } $result += Invoke-BPARestMethod @tempSplat } default { $unsupportedType = $obj.GetType().FullName if ($_) { $unsupportedType = $_ } elseif (($null -ne $obj.Type) -and ($obj.Type -ne "")) { $unsupportedType = $obj.Type } Write-Error -Message "Unsupported input type '$unsupportedType' encountered!" -TargetObject $obj } } } } } } END { $result | Foreach-Object {$_.PSObject.TypeNames.Insert(0,"BPAConstructType.Calendar")} $SortProperty += "BPAServer", "ID" return $result | Sort-Object $SortProperty -Unique -Descending:$SortDescending.ToBool() } } |