Skip to content

Commit 51a454b

Browse files
committed
Merge branch 'docs/samples-standardize-definitions-with-test-definitions'
2 parents cbaf0c9 + e1fb43c commit 51a454b

3 files changed

Lines changed: 80 additions & 80 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ The properties of definition objects are based off the parameters of the followi
5151
* [`New-ScheduledTaskSettingsSet`](https://docs.microsoft.com/en-us/powershell/module/scheduledtasks/new-scheduledtasksettingsset)
5252
* [`New-ScheduledTaskPrincipal`](https://docs.microsoft.com/en-us/powershell/module/scheduledtasks/new-scheduledtaskprincipal)
5353

54-
Several parameters such as [`-At`](src/ScheduledTaskManagement/Private/Serialize-DefinitionObject.ps1#L19-L27) of `New-ScheduledTaskTrigger` involve values whose types prevent them from being expressed purely in non-PowerShell code. The module accounts for such values by allowing them to be *intuitively* yet [*declaratively* defined](docs/samples/definitions/scheduledtasks/tasks.sample.json#L51-L63). Those values will be converted into their relevant PowerShell types as part of the module's serialization process right before task creation or application. Through so, scheduled tasks can be managed as code as part of the practice of [Infrastructure-as-Code (IaC)](https://en.wikipedia.org/wiki/Infrastructure_as_code).
54+
Several parameters such as [`-At`](src/ScheduledTaskManagement/Private/Serialize-DefinitionObject.ps1#L19-L27) of `New-ScheduledTaskTrigger` involve values whose types prevent them from being expressed purely in non-PowerShell code. The module accounts for such values by allowing them to be *intuitively* yet [*declaratively* defined](docs/samples/definitions/scheduledtasks/tasks.sample.json#L57-L70). Those values will be converted into their relevant PowerShell types as part of the module's serialization process right before task creation or application. Through so, scheduled tasks can be managed as code as part of the practice of [Infrastructure-as-Code (IaC)](https://en.wikipedia.org/wiki/Infrastructure_as_code).
5555

5656
Sample definition files can be found [here](docs/samples/definitions/scheduledtasks).
5757

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,163 +1,163 @@
11
[
22
{
3+
"TaskPath": "\\MyTaskFolder\\",
4+
"Principal": {
5+
"LogonType": "S4U",
6+
"RunLevel": "Highest",
7+
"UserId": "myusername"
8+
},
39
"Settings": {
10+
"Disable": false,
411
"AllowStartIfOnBatteries": true,
5-
"DontStopIfGoingOnBatteries": true,
6-
"Disable": false
12+
"DontStopIfGoingOnBatteries": true
713
},
814
"Trigger": [
915
{
1016
"AtStartup": true
1117
},
1218
{
13-
"DaysInterval": 1,
1419
"At": {
20+
"Hour": 17,
1521
"Minute": 30,
16-
"Month": 11,
22+
"Second": 0,
1723
"Day": 30,
1824
"Year": 1999,
19-
"Hour": 17,
20-
"Second": 0
25+
"Month": 11
2126
},
22-
"Daily": true
27+
"Daily": true,
28+
"DaysInterval": 1
2329
}
2430
],
25-
"TaskName": "MyTaskName1",
26-
"Principal": {
27-
"UserId": "myusername",
28-
"LogonType": "S4U",
29-
"RunLevel": "Highest"
30-
},
3131
"Action": [
3232
{
33-
"Argument": "-NonInteractive -NoProfile -NoLogo -Command 'New-Item \"$env:TEMP\\$(Get-Date -UFormat .%s.1)\"'",
34-
"Execute": "powershell"
33+
"Execute": "powershell",
34+
"Argument": "-NonInteractive -NoProfile -NoLogo -Command 'New-Item \"$env:TEMP\\$(Get-Date -UFormat .%s-1-1)\"'"
3535
},
3636
{
37-
"Argument": "-NonInteractive -NoProfile -NoLogo -Command 'New-Item \"$env:TEMP\\$(Get-Date -UFormat .%s.2)\"'",
38-
"Execute": "powershell"
37+
"Execute": "powershell",
38+
"Argument": "-NonInteractive -NoProfile -NoLogo -Command 'New-Item \"$env:TEMP\\$(Get-Date -UFormat .%s-1-2)\"'"
3939
}
4040
],
41-
"TaskPath": "\\MyTaskFolder\\"
41+
"TaskName": "MyTaskName1"
4242
},
4343
{
44+
"TaskPath": "\\MyTaskFolder\\",
45+
"Principal": {
46+
"LogonType": "S4U",
47+
"RunLevel": "Limited",
48+
"UserId": "NT AUTHORITY\\SYSTEM"
49+
},
4450
"Settings": {
51+
"Disable": false,
4552
"AllowStartIfOnBatteries": true,
46-
"DontStopIfGoingOnBatteries": true,
47-
"Disable": false
53+
"DontStopIfGoingOnBatteries": true
4854
},
4955
"Trigger": [
5056
{
5157
"At": {
58+
"Hour": 14,
5259
"Minute": 0,
53-
"Month": 11,
60+
"Second": 0,
5461
"Day": 30,
5562
"Year": 1999,
56-
"Hour": 14,
57-
"Second": 0
63+
"Month": 11
5864
},
65+
"Once": true,
5966
"RepetitionInterval": {
60-
"Minute": 0,
6167
"Hour": 12,
68+
"Minute": 0,
6269
"Second": 0
63-
},
64-
"Once": true
70+
}
6571
}
6672
],
67-
"TaskName": "MyTaskName2",
68-
"Principal": {
69-
"UserId": "NT AUTHORITY\\SYSTEM",
70-
"LogonType": "S4U",
71-
"RunLevel": "Limited"
72-
},
7373
"Action": [
7474
{
75-
"Argument": "-NonInteractive -NoProfile -NoLogo -Command 'New-Item \"$env:TEMP\\$(Get-Date -UFormat .%s.1)\"'",
76-
"Execute": "powershell"
75+
"Execute": "powershell",
76+
"Argument": "-NonInteractive -NoProfile -NoLogo -Command 'New-Item \"$env:TEMP\\$(Get-Date -UFormat .%s-2-1)\"'"
7777
},
7878
{
79-
"Argument": "-NonInteractive -NoProfile -NoLogo -Command 'New-Item \"$env:TEMP\\$(Get-Date -UFormat .%s.2)\"'",
80-
"Execute": "powershell"
79+
"Execute": "powershell",
80+
"Argument": "-NonInteractive -NoProfile -NoLogo -Command 'New-Item \"$env:TEMP\\$(Get-Date -UFormat .%s-2-2)\"'"
8181
}
8282
],
83-
"TaskPath": "\\MyTaskFolder\\"
83+
"TaskName": "MyTaskName2"
8484
},
8585
{
86+
"TaskPath": "\\MyTaskFolder\\",
87+
"Principal": {
88+
"LogonType": "S4U",
89+
"RunLevel": "Highest",
90+
"UserId": "myusername"
91+
},
8692
"Settings": {
93+
"Disable": false,
8794
"AllowStartIfOnBatteries": true,
88-
"DontStopIfGoingOnBatteries": true,
89-
"Disable": false
95+
"DontStopIfGoingOnBatteries": true
9096
},
9197
"Trigger": [
9298
{
93-
"DaysInterval": 1,
9499
"At": {
100+
"Hour": 10,
95101
"Minute": 0,
96-
"Month": 11,
102+
"Second": 0,
97103
"Day": 30,
98104
"Year": 1999,
99-
"Hour": 10,
100-
"Second": 0
105+
"Month": 11
101106
},
102-
"Daily": true
107+
"Daily": true,
108+
"DaysInterval": 1
103109
},
104110
{
105-
"DaysInterval": 1,
106111
"At": {
112+
"Hour": 14,
107113
"Minute": 0,
108-
"Month": 11,
114+
"Second": 0,
109115
"Day": 30,
110116
"Year": 1999,
111-
"Hour": 14,
112-
"Second": 0
117+
"Month": 11
113118
},
114-
"Daily": true
119+
"Daily": true,
120+
"DaysInterval": 1
115121
},
116122
{
117-
"DaysInterval": 1,
118123
"At": {
124+
"Hour": 18,
119125
"Minute": 0,
120-
"Month": 11,
126+
"Second": 0,
121127
"Day": 30,
122128
"Year": 1999,
123-
"Hour": 18,
124-
"Second": 0
129+
"Month": 11
125130
},
126-
"Daily": true
131+
"Daily": true,
132+
"DaysInterval": 1
127133
},
128134
{
129-
"DaysInterval": 1,
130135
"At": {
136+
"Hour": 22,
131137
"Minute": 0,
132-
"Month": 11,
138+
"Second": 0,
133139
"Day": 30,
134140
"Year": 1999,
135-
"Hour": 22,
136-
"Second": 0
141+
"Month": 11
137142
},
138-
"Daily": true
143+
"Daily": true,
144+
"DaysInterval": 1
139145
}
140146
],
141-
"TaskName": "MyTaskName3",
142-
"Principal": {
143-
"UserId": "myusername",
144-
"LogonType": "S4U",
145-
"RunLevel": "Highest"
146-
},
147147
"Action": [
148148
{
149-
"Argument": "-NonInteractive -NoProfile -NoLogo -Command 'New-Item \"$env:TEMP\\$(Get-Date -UFormat .%s.1)\"'",
150-
"Execute": "powershell"
149+
"Execute": "powershell",
150+
"Argument": "-NonInteractive -NoProfile -NoLogo -Command 'New-Item \"$env:TEMP\\$(Get-Date -UFormat .%s-3-1)\"'"
151151
},
152152
{
153-
"Argument": "-NonInteractive -NoProfile -NoLogo -Command 'New-Item \"$env:TEMP\\$(Get-Date -UFormat .%s.2)\"'",
154-
"Execute": "powershell"
153+
"Execute": "powershell",
154+
"Argument": "-NonInteractive -NoProfile -NoLogo -Command 'New-Item \"$env:TEMP\\$(Get-Date -UFormat .%s-3-2)\"'"
155155
},
156156
{
157-
"Argument": "-NonInteractive -NoProfile -NoLogo -Command 'New-Item \"$env:TEMP\\$(Get-Date -UFormat .%s.3)\"'",
158-
"Execute": "powershell"
157+
"Execute": "powershell",
158+
"Argument": "-NonInteractive -NoProfile -NoLogo -Command 'New-Item \"$env:TEMP\\$(Get-Date -UFormat .%s-3-3)\"'"
159159
}
160160
],
161-
"TaskPath": "\\MyTaskFolder\\"
161+
"TaskName": "MyTaskName3"
162162
}
163163
]

docs/samples/definitions/scheduledtasks/tasks.sample.ps1

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@
5252
@{
5353
Execute = 'powershell'
5454
Argument = @'
55-
-NonInteractive -NoProfile -NoLogo -Command 'New-Item "$env:TEMP\$(Get-Date -UFormat .%s.1)"'
55+
-NonInteractive -NoProfile -NoLogo -Command 'New-Item "$env:TEMP\$(Get-Date -UFormat .%s-1-1)"'
5656
'@
5757
}
5858
@{
5959
Execute = 'powershell'
6060
Argument = @'
61-
-NonInteractive -NoProfile -NoLogo -Command 'New-Item "$env:TEMP\$(Get-Date -UFormat .%s.2)"'
61+
-NonInteractive -NoProfile -NoLogo -Command 'New-Item "$env:TEMP\$(Get-Date -UFormat .%s-1-2)"'
6262
'@
6363
}
6464
)
@@ -105,13 +105,13 @@
105105
@{
106106
Execute = 'powershell'
107107
Argument = @'
108-
-NonInteractive -NoProfile -NoLogo -Command 'New-Item "$env:TEMP\$(Get-Date -UFormat .%s.1)"'
108+
-NonInteractive -NoProfile -NoLogo -Command 'New-Item "$env:TEMP\$(Get-Date -UFormat .%s-2-1)"'
109109
'@
110110
}
111111
@{
112112
Execute = 'powershell'
113113
Argument = @'
114-
-NonInteractive -NoProfile -NoLogo -Command 'New-Item "$env:TEMP\$(Get-Date -UFormat .%s.2)"'
114+
-NonInteractive -NoProfile -NoLogo -Command 'New-Item "$env:TEMP\$(Get-Date -UFormat .%s-2-2)"'
115115
'@
116116
}
117117
)
@@ -224,19 +224,19 @@
224224
@{
225225
Execute = 'powershell'
226226
Argument = @'
227-
-NonInteractive -NoProfile -NoLogo -Command 'New-Item "$env:TEMP\$(Get-Date -UFormat .%s.1)"'
227+
-NonInteractive -NoProfile -NoLogo -Command 'New-Item "$env:TEMP\$(Get-Date -UFormat .%s-3-1)"'
228228
'@
229229
}
230230
@{
231231
Execute = 'powershell'
232232
Argument = @'
233-
-NonInteractive -NoProfile -NoLogo -Command 'New-Item "$env:TEMP\$(Get-Date -UFormat .%s.2)"'
233+
-NonInteractive -NoProfile -NoLogo -Command 'New-Item "$env:TEMP\$(Get-Date -UFormat .%s-3-2)"'
234234
'@
235235
}
236236
@{
237237
Execute = 'powershell'
238238
Argument = @'
239-
-NonInteractive -NoProfile -NoLogo -Command 'New-Item "$env:TEMP\$(Get-Date -UFormat .%s.3)"'
239+
-NonInteractive -NoProfile -NoLogo -Command 'New-Item "$env:TEMP\$(Get-Date -UFormat .%s-3-3)"'
240240
'@
241241
}
242242
)

0 commit comments

Comments
 (0)