Scripts/Add-BPAScheduleConditionHoliday.ps1

function Add-BPAScheduleConditionHoliday {    
    <#
        .SYNOPSIS
            Adds a holiday to an AutoMate BPA schedule condition using the Holidays interval.
 
        .DESCRIPTION
            Add-BPAScheduleConditionHoliday adds a holiday to an AutoMate BPA schedule condition using the Holidays interval.
 
        .PARAMETER InputObject
            The schedule condition object to add the holiday to.
 
        .PARAMETER Holiday
            The holiday categories to add to the schedule.
 
        .EXAMPLE
            # Add a holiday category to schedule "On Specified Dates"
            Get-BPACondition "On Specified Dates" | Add-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 -notcontains $h) {
                        $update.HolidayList += $h
                        $shouldUpdate = $true
                    } else {
                        Write-Warning "$($obj.TriggerType -as [BPATriggerType]) $($obj.TypeName) '$($obj.Name)' already contains holiday category $h!"
                    }
                }
                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
            }
        }
    }
}