Scripts/Add-BPAScheduleConditionCustomDate.ps1
function Add-BPAScheduleConditionCustomDate { <# .SYNOPSIS Adds a custom date to an AutoMate BPA schedule condition using the Custom interval. .DESCRIPTION Add-BPAScheduleConditionCustomDate adds a custom date to an AutoMate BPA schedule condition using the Custom interval. .PARAMETER InputObject The schedule condition object to add the custom date to. .PARAMETER CustomLaunchDates The dates to add to the schedule. .EXAMPLE # Add a custom run time of 1 hour from now to schedule "On Specified Dates" Get-BPACondition "On Specified Dates" | Add-BPAScheduleConditionCustomDate -CustomLaunchDates (Get-Date).AddHours(1) .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()] [DateTime[]]$CustomLaunchDates ) PROCESS { foreach ($obj in $InputObject) { if (($obj.TypeName -eq "Condition") -and ($obj.TriggerType -eq [BPATriggerType]::Schedule.value__) -and ($obj.ScheduleType -eq [BPAScheduleType]::Custom.value__)) { $update = Get-BPACondition -ID $obj.ID -BPAServer $obj.BPAServer $update.Day += $CustomLaunchDates | ForEach-Object { Get-Date $_ -Format $BPAScheduleDateFormat } $update | Set-BPAObject } else { Write-Error -Message "Unsupported input type '$($obj.TypeName)' and trigger type '$($obj.TriggerType -as [BPATriggerType])' encountered!" -TargetObject $obj } } } } |