You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: public/New-DbaAgentSchedule.ps1
+60Lines changed: 60 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -88,6 +88,23 @@ function New-DbaAgentSchedule {
88
88
89
89
FrequencyRecurrenceFactor is used only if FrequencyType is "Weekly", "Monthly" or "MonthlyRelative".
90
90
91
+
.PARAMETERFrequencyText
92
+
Describe common frequencies as a text. Sample text:
93
+
94
+
Every minute
95
+
Every 5 minutes
96
+
Every 10 minutes starting at 00:02:30
97
+
Every hour
98
+
Every 2 hours
99
+
Every 4 hours starting at 02:00:00
100
+
Every day at 05:00:00
101
+
Every sunday at 02:00:00
102
+
103
+
This is the used regex: every(\s+(?<interval>\d+))?\s+(?<unit>minute|hour|day|sunday|monday|tuesday|wednesday|thursday|friday|saturday)s?(\s+starting)?(\s+at\s+(?<start>\d\d:\d\d:\d\d))?
104
+
105
+
If parameter Schedule is not provided, the FrequencyText will be used as the name of the schedule.
106
+
Parameter Force will be set to $true.
107
+
91
108
.PARAMETERStartDate
92
109
The earliest date this schedule can execute jobs, formatted as yyyyMMdd (e.g., "20240315" for March 15, 2024).
93
110
Use this to delay schedule activation until a future date or to document when recurring maintenance should begin.
@@ -157,6 +174,12 @@ function New-DbaAgentSchedule {
@@ -188,6 +212,42 @@ function New-DbaAgentSchedule {
188
212
begin {
189
213
if ($Force) { $ConfirmPreference='none' }
190
214
215
+
if ($FrequencyText) {
216
+
if ($FrequencyText-match'every(\s+(?<interval>\d+))?\s+(?<unit>minute|hour|day|sunday|monday|tuesday|wednesday|thursday|friday|saturday)s?(\s+starting)?(\s+at\s+(?<start>\d\d:\d\d:\d\d))?') {
217
+
$textInterval=$Matches['interval']
218
+
$textUnit=$Matches['unit']
219
+
$textStart=$Matches['start']
220
+
221
+
if (-not$textInterval) {
222
+
$textInterval=1
223
+
}
224
+
225
+
if ($textUnit-in'minute','hour','day') {
226
+
$FrequencyType='Daily'
227
+
if ($textUnit-in'minute','hour') {
228
+
$FrequencySubdayType=$textUnit
229
+
$FrequencySubdayInterval=$textInterval
230
+
}
231
+
} else {
232
+
$FrequencyType='Weekly'
233
+
$FrequencyInterval=$textUnit
234
+
}
235
+
236
+
if ($textStart) {
237
+
$StartTime=$textStart.Replace(':','')
238
+
}
239
+
240
+
if (-not$Schedule) {
241
+
$Schedule=$FrequencyText
242
+
}
243
+
244
+
$Force=$true
245
+
} else {
246
+
Stop-Function-Message "FrequencyText can not be parsed."
247
+
return
248
+
}
249
+
}
250
+
191
251
if ($FrequencyType-eq"Daily"-and-not$FrequencyInterval) {
0 commit comments