Scripts/Remove-BPAScheduleConditionHoliday.ps1
function Remove-BPAScheduleConditionHoliday { <# .SYNOPSIS Removes a holiday from an AutoMate BPA schedule condition using the Holidays interval. .DESCRIPTION Remove-BPAScheduleConditionHoliday removes a holiday from an AutoMate BPA schedule condition using the Holidays interval. .PARAMETER InputObject The schedule condition object to remove the holiday from. .PARAMETER Holiday The holiday categories to remove from the schedule. .EXAMPLE # Add a holiday category to schedule "On Specified Dates" Get-BPACondition "On Specified Dates" | Remove-BPAScheduleConditionHoliday -Holiday "United States" .NOTES Author(s): : David Seibel Contributor(s) : Date Created : 07/13/2017 Date Modified : 02/08/2018 .LINK https://github.com/davidseibel/PoshBPA #> [CmdletBinding(DefaultParameterSetName = "Default")] param( [Parameter(Mandatory = $true, ValueFromPipeline = $true)] $InputObject, [Parameter(Mandatory = $true, Position = 0)] [ValidateNotNullOrEmpty()] [string[]]$Holiday ) PROCESS { foreach ($obj in $InputObject) { if (($obj.TypeName -eq "Condition") -and ($obj.TriggerType -eq [BPATriggerType]::Schedule.value__) -and ($obj.ScheduleType -eq [BPAScheduleType]::Holidays.value__)) { $update = Get-BPACondition -ID $obj.ID -BPAServer $obj.BPAServer $shouldUpdate = $false foreach ($h in $Holiday) { if ($update.HolidayList -contains $h) { $update.HolidayList = @($update.HolidayList | Where-Object {$_ -ne $h}) $shouldUpdate = $true } else { Write-Warning "$($obj.TriggerType -as [BPATriggerType]) $($obj.TypeName) '$($obj.Name)' does not contain holiday category $h!" } } if ($update.HolidayList.Count -eq 0) { $shouldUpdate = $false throw "A schedule condition using the Holiday interval must have at least 1 holiday category specified!" } if ($shouldUpdate) { $update | Set-BPAObject } else { Write-Verbose "$($obj.TriggerType -as [BPATriggerType]) $($obj.TypeName) '$($obj.Name)' already contains the specified values." } } else { Write-Error -Message "Unsupported input type '$($obj.TypeName)' and trigger type '$($obj.TriggerType -as [BPATriggerType])' encountered!" -TargetObject $obj } } } } |