@@ -6,30 +6,73 @@ function Set-CIPPVacationOOO {
66 [string ]$InternalMessage ,
77 [string ]$ExternalMessage ,
88 [string ]$APIName = ' OOO Vacation Mode' ,
9- $Headers
9+ $Headers ,
10+ $StartTime ,
11+ $EndTime ,
12+ [bool ]$CreateOOFEvent ,
13+ [string ]$OOFEventSubject ,
14+ [bool ]$AutoDeclineFutureRequestsWhenOOF ,
15+ [bool ]$DeclineEventsForScheduledOOF ,
16+ [bool ]$DeclineAllEventsForScheduledOOF ,
17+ [string ]$DeclineMeetingMessage
1018 )
1119
1220 $Results = [System.Collections.Generic.List [string ]]::new()
1321
1422 foreach ($upn in $Users ) {
1523 if ([string ]::IsNullOrWhiteSpace($upn )) { continue }
1624 try {
25+ # Use Scheduled when StartTime/EndTime are provided (vacation always has dates),
26+ # otherwise fall back to Enabled for backwards compatibility with in-flight tasks
27+ $State = if ($Action -eq ' Add' ) {
28+ if ($PSBoundParameters.ContainsKey (' StartTime' ) -and $PSBoundParameters.ContainsKey (' EndTime' )) { ' Scheduled' } else { ' Enabled' }
29+ } else { ' Disabled' }
30+
1731 $SplatParams = @ {
1832 UserID = $upn
1933 TenantFilter = $TenantFilter
20- State = if ( $Action -eq ' Add ' ) { ' Enabled ' } else { ' Disabled ' }
34+ State = $State
2135 APIName = $APIName
2236 Headers = $Headers
2337 }
24- # Only pass messages on Add — Remove only disables, preserving any messages
25- # the user may have updated themselves during vacation
38+
2639 if ($Action -eq ' Add' ) {
40+ # Pass start/end times when available
41+ if ($PSBoundParameters.ContainsKey (' StartTime' )) {
42+ $SplatParams.StartTime = $StartTime
43+ }
44+ if ($PSBoundParameters.ContainsKey (' EndTime' )) {
45+ $SplatParams.EndTime = $EndTime
46+ }
47+
48+ # Only pass messages on Add — Remove only disables, preserving any messages
49+ # the user may have updated themselves during vacation
2750 if (-not [string ]::IsNullOrWhiteSpace($InternalMessage )) {
2851 $SplatParams.InternalMessage = $InternalMessage
2952 }
3053 if (-not [string ]::IsNullOrWhiteSpace($ExternalMessage )) {
3154 $SplatParams.ExternalMessage = $ExternalMessage
3255 }
56+
57+ # Calendar options — pass through when explicitly provided
58+ if ($PSBoundParameters.ContainsKey (' CreateOOFEvent' )) {
59+ $SplatParams.CreateOOFEvent = $CreateOOFEvent
60+ }
61+ if ($PSBoundParameters.ContainsKey (' OOFEventSubject' )) {
62+ $SplatParams.OOFEventSubject = $OOFEventSubject
63+ }
64+ if ($PSBoundParameters.ContainsKey (' AutoDeclineFutureRequestsWhenOOF' )) {
65+ $SplatParams.AutoDeclineFutureRequestsWhenOOF = $AutoDeclineFutureRequestsWhenOOF
66+ }
67+ if ($PSBoundParameters.ContainsKey (' DeclineEventsForScheduledOOF' )) {
68+ $SplatParams.DeclineEventsForScheduledOOF = $DeclineEventsForScheduledOOF
69+ }
70+ if ($PSBoundParameters.ContainsKey (' DeclineAllEventsForScheduledOOF' )) {
71+ $SplatParams.DeclineAllEventsForScheduledOOF = $DeclineAllEventsForScheduledOOF
72+ }
73+ if ($PSBoundParameters.ContainsKey (' DeclineMeetingMessage' )) {
74+ $SplatParams.DeclineMeetingMessage = $DeclineMeetingMessage
75+ }
3376 }
3477 $result = Set-CIPPOutOfOffice @SplatParams
3578 $Results.Add ($result )
0 commit comments