Scripts/Set-BPAScheduleCondition.ps1

function Set-BPAScheduleCondition {    
    <#
        .SYNOPSIS
            Sets properties of an AutoMate BPA schedule condition.
 
        .DESCRIPTION
            Sets-BPAScheduleCondition modifies an existing schedule condition.
 
        .PARAMETER InputObject
            The condition to modify.
 
        .PARAMETER ScheduleType
            Set the schedule to use a Custom interval.
 
        .PARAMETER NextLaunchDate
            The next time the schedule will execute
 
        .PARAMETER Frequency
            How frequently the schedule should execute the specified interval. For example: every 1 day, every 2 days, etc.
 
        .PARAMETER Day
            The day(s) of the week to execute the schedule on.
 
        .PARAMETER End
            The last date the schedule will execute.
 
        .PARAMETER Measure
            When using the -MonthInterval option, use this parameter to specify regular days, work days, or a specific weekday (i.e. Monday, Tuesday, etc.).
 
        .PARAMETER Month
            The month(s) to execute.
 
        .PARAMETER MonthInterval
            The frequency to execute when using a "Specific day(s) of the month" schedule type.
 
        .PARAMETER OnTaskLate
            The action to take when the task is late.
 
        .PARAMETER Reschedule
            Specify how the schedule should be rescheduled.
 
        .PARAMETER Notes
            The new notes to set on the object.
 
        .EXAMPLE
            # Set schedule "Daily at 8PM" to disable the trigger when late
            Get-BPACondition "Daily at 8PM" | Set-BPAScheduleCondition -ScheduleType Day -OnTaskLate DisableTrigger
 
        .NOTES
            Author(s): : David Seibel
            Contributor(s) :
            Date Created : 07/13/2017
            Date Modified : 03/27/2018
 
        .LINK
            https://github.com/davidseibel/PoshBPA
    #>

    [CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact="Medium",DefaultParameterSetName="Default")]
    param(
        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
        $InputObject,

        [ValidateNotNullOrEmpty()]
        [BPAScheduleType]$ScheduleType,

        [ValidateNotNullOrEmpty()]
        [DateTime]$NextLaunchDate,

        [ValidateSet(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,"first","second","third","fourth","last")]
        $Frequency,

        [DayOfWeek[]]$Day,

        [DateTime]$End,

        [ValidateNotNullOrEmpty()]
        [BPAScheduleMeasure]$Measure,

        [ValidateSet("January","February","March","April","May","June","July","August","September","October","November","December")]
        [string[]]$Month,

        [ValidateNotNullOrEmpty()]
        [int]$MonthInterval,

        [ValidateNotNullOrEmpty()]
        [BPAOnTaskLateRescheduleOption]$OnTaskLate = [BPAOnTaskLateRescheduleOption]::RunImmediately,

        [ValidateNotNullOrEmpty()]
        [BPARescheduleOption]$Reschedule = [BPARescheduleOption]::RelativeToOriginalTime,

        [string]$Notes
    )

    PROCESS {
        foreach ($obj in $InputObject) {
            if ($obj.TypeName -eq "Condition" -and $obj.TriggerType -eq [BPATriggerType]::Schedule.value__) {
                $updateObject = Get-BPACondition -ID $obj.ID -BPAServer $obj.BPAServer
                $shouldUpdate = $false
                $boundParameterKeys = $PSBoundParameters.Keys | Where-Object {($_ -notin "InputObject","BPAServer") -and `
                                                                              ($_ -notin [System.Management.Automation.PSCmdlet]::CommonParameters) -and `
                                                                              ($_ -notin [System.Management.Automation.PSCmdlet]::OptionalCommonParameters)}
                foreach ($boundParameterKey in $boundParameterKeys) {
                    $property = $boundParameterKey
                    $value = $PSBoundParameters[$property]

                    # Handle special property types
                    if ($value -is [System.Management.Automation.SwitchParameter]) { $value = $value.ToBool() }
                    elseif ($value -is [System.Enum])                              { $value = $value.value__  }
                    elseif ($value -is [DateTime])                                 { $value = Get-Date $value -Format $BPAScheduleDateFormat }
                    elseif ($property -eq "Day") {
                        $value = ($Day -join ",").ToLower() -split ","
                        $updateObject."$property" = $value
                        $shouldUpdate = $true
                    }

                    # Compare and change properties
                    if ($updateObject."$property" -ne $value) {
                        $updateObject."$property" = $value
                        $shouldUpdate = $true
                    }
                }

                if ($shouldUpdate) {
                    $updateObject | Set-BPAObject
                } else {
                    Write-Verbose "$($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
            }
        }
    }
}