From f3879ace1363be94313be8ff5540cc3d23b15128 Mon Sep 17 00:00:00 2001 From: Joel Timothy Oh Date: Tue, 27 Sep 2022 14:12:11 +0000 Subject: [PATCH] Fix (definitions): Revise to use strings instead of here-strings for definition object action command arguments This change will keep the definition object format in line with the design of task scheduler which only accepts a string for task action command arguments. With the discovery made in 31679d2a14211e6e34a7d0bac4bc58b5f45a5c63, it is now apparent that single-quotes cannot be used in task action command arguments. The reusability of command argument code is thus limited and renders little use for here-strings. This change also partially reverts changes in 46e51c01b9becc2a9e5a239a5e744fdb95645ba4. --- README.md | 2 +- .../scheduledtasks/tasks.sample.json | 182 +++++++++--------- .../scheduledtasks/tasks.sample.ps1 | 28 +-- test/definitions/scheduledtasks/tasks-1.json | 182 +++++++++--------- test/definitions/scheduledtasks/tasks-1.ps1 | 28 +-- test/definitions/scheduledtasks/tasks-2.json | 182 +++++++++--------- test/definitions/scheduledtasks/tasks-2.ps1 | 28 +-- 7 files changed, 295 insertions(+), 337 deletions(-) diff --git a/README.md b/README.md index 492d384..c020577 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ The properties of definition objects are based off the parameters of the followi * [`New-ScheduledTaskSettingsSet`](https://docs.microsoft.com/en-us/powershell/module/scheduledtasks/new-scheduledtasksettingsset) * [`New-ScheduledTaskPrincipal`](https://docs.microsoft.com/en-us/powershell/module/scheduledtasks/new-scheduledtaskprincipal) -Several parameters such as [`-At`](https://learn.microsoft.com/en-us/powershell/module/scheduledtasks/new-scheduledtasktrigger#-at) of `New-ScheduledTaskTrigger` involve values whose types prevent them from being expressed purely in non-PowerShell code. The module accounts for such values by enabling them to be intuitively yet declaratively defined even in [`.json`](docs/samples/definitions/scheduledtasks/tasks.sample.json#L57-L70) format. Those values will be *converted* into their relevant PowerShell types as part of a [serialization process](src/ScheduledTaskManagement/Private/Serialize-DefinitionObject.ps1#L19-L27) 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). +Several parameters such as [`-At`](https://learn.microsoft.com/en-us/powershell/module/scheduledtasks/new-scheduledtasktrigger#-at) of `New-ScheduledTaskTrigger` involve values whose types prevent them from being expressed purely in non-PowerShell code. The module accounts for such values by enabling them to be intuitively yet declaratively defined even in [`.json`](docs/samples/definitions/scheduledtasks/tasks.sample.json#L49-L61) format. Those values will be *converted* into their relevant PowerShell types as part of a [serialization process](src/ScheduledTaskManagement/Private/Serialize-DefinitionObject.ps1#L19-L27) 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). Sample definition files can be found [here](docs/samples/definitions/scheduledtasks). diff --git a/docs/samples/definitions/scheduledtasks/tasks.sample.json b/docs/samples/definitions/scheduledtasks/tasks.sample.json index 0fb2459..818dc32 100644 --- a/docs/samples/definitions/scheduledtasks/tasks.sample.json +++ b/docs/samples/definitions/scheduledtasks/tasks.sample.json @@ -1,163 +1,163 @@ [ { "TaskName": "MyTaskName1", - "Action": [ - { - "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-1-1)\\\"\"", - "Execute": "powershell" - }, - { - "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-1-2)\\\"\"", - "Execute": "powershell" - } - ], + "TaskPath": "\\MyTaskFolder\\", "Trigger": [ { "AtStartup": true }, { + "DaysInterval": 1, + "Daily": true, "At": { + "Day": 30, + "Second": 0, "Year": 1999, - "Hour": 17, "Minute": 30, - "Second": 0, - "Day": 30, + "Hour": 17, "Month": 11 - }, - "Daily": true, - "DaysInterval": 1 + } + } + ], + "Action": [ + { + "Execute": "powershell", + "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-1-1)\\\"\"" + }, + { + "Execute": "powershell", + "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-1-2)\\\"\"" } ], - "Settings": { - "DontStopIfGoingOnBatteries": true, - "Disable": false, - "AllowStartIfOnBatteries": true - }, "Principal": { - "UserId": "myusername", "LogonType": "S4U", + "UserId": "myusername", "RunLevel": "Highest" }, - "TaskPath": "\\MyTaskFolder\\" + "Settings": { + "Disable": false, + "DontStopIfGoingOnBatteries": true, + "AllowStartIfOnBatteries": true + } }, { "TaskName": "MyTaskName2", - "Action": [ - { - "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-2-1)\\\"\"", - "Execute": "powershell" - }, - { - "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-2-2)\\\"\"", - "Execute": "powershell" - } - ], + "TaskPath": "\\MyTaskFolder\\", "Trigger": [ { + "Once": true, "At": { + "Day": 30, + "Second": 0, "Year": 1999, - "Hour": 14, "Minute": 0, - "Second": 0, - "Day": 30, + "Hour": 14, "Month": 11 }, - "Once": true, "RepetitionInterval": { - "Minute": 0, + "Second": 0, "Hour": 12, - "Second": 0 + "Minute": 0 } } ], - "Settings": { - "DontStopIfGoingOnBatteries": true, - "Disable": false, - "AllowStartIfOnBatteries": true - }, + "Action": [ + { + "Execute": "powershell", + "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-2-1)\\\"\"" + }, + { + "Execute": "powershell", + "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-2-2)\\\"\"" + } + ], "Principal": { - "UserId": "NT AUTHORITY\\SYSTEM", "LogonType": "S4U", + "UserId": "NT AUTHORITY\\SYSTEM", "RunLevel": "Limited" }, - "TaskPath": "\\MyTaskFolder\\" + "Settings": { + "Disable": false, + "DontStopIfGoingOnBatteries": true, + "AllowStartIfOnBatteries": true + } }, { "TaskName": "MyTaskName3", - "Action": [ - { - "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-3-1)\\\"\"", - "Execute": "powershell" - }, - { - "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-3-2)\\\"\"", - "Execute": "powershell" - }, - { - "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-3-3)\\\"\"", - "Execute": "powershell" - } - ], + "TaskPath": "\\MyTaskFolder\\", "Trigger": [ { + "DaysInterval": 1, + "Daily": true, "At": { + "Day": 30, + "Second": 0, "Year": 1999, - "Hour": 10, "Minute": 0, - "Second": 0, - "Day": 30, + "Hour": 10, "Month": 11 - }, - "Daily": true, - "DaysInterval": 1 + } }, { + "DaysInterval": 1, + "Daily": true, "At": { + "Day": 30, + "Second": 0, "Year": 1999, - "Hour": 14, "Minute": 0, - "Second": 0, - "Day": 30, + "Hour": 14, "Month": 11 - }, - "Daily": true, - "DaysInterval": 1 + } }, { + "DaysInterval": 1, + "Daily": true, "At": { + "Day": 30, + "Second": 0, "Year": 1999, - "Hour": 18, "Minute": 0, - "Second": 0, - "Day": 30, + "Hour": 18, "Month": 11 - }, - "Daily": true, - "DaysInterval": 1 + } }, { + "DaysInterval": 1, + "Daily": true, "At": { + "Day": 30, + "Second": 0, "Year": 1999, - "Hour": 22, "Minute": 0, - "Second": 0, - "Day": 30, + "Hour": 22, "Month": 11 - }, - "Daily": true, - "DaysInterval": 1 + } + } + ], + "Action": [ + { + "Execute": "powershell", + "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-3-1)\\\"\"" + }, + { + "Execute": "powershell", + "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-3-2)\\\"\"" + }, + { + "Execute": "powershell", + "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-3-3)\\\"\"" } ], - "Settings": { - "DontStopIfGoingOnBatteries": true, - "Disable": false, - "AllowStartIfOnBatteries": true - }, "Principal": { - "UserId": "myusername", "LogonType": "S4U", + "UserId": "myusername", "RunLevel": "Highest" }, - "TaskPath": "\\MyTaskFolder\\" + "Settings": { + "Disable": false, + "DontStopIfGoingOnBatteries": true, + "AllowStartIfOnBatteries": true + } } ] diff --git a/docs/samples/definitions/scheduledtasks/tasks.sample.ps1 b/docs/samples/definitions/scheduledtasks/tasks.sample.ps1 index 4ce1590..6ae2a53 100644 --- a/docs/samples/definitions/scheduledtasks/tasks.sample.ps1 +++ b/docs/samples/definitions/scheduledtasks/tasks.sample.ps1 @@ -51,15 +51,11 @@ Action = @( @{ Execute = 'powershell' - Argument = @' --NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-1-1)\"" -'@ + Argument = '-NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-1-1)\""' } @{ Execute = 'powershell' - Argument = @' --NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-1-2)\"" -'@ + Argument = '-NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-1-2)\""' } ) Settings = @{ @@ -103,15 +99,11 @@ Action = @( @{ Execute = 'powershell' - Argument = @' --NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-2-1)\"" -'@ + Argument = '-NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-2-1)\""' } @{ Execute = 'powershell' - Argument = @' --NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-2-2)\"" -'@ + Argument = '-NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-2-2)\""' } ) Settings = @{ @@ -221,21 +213,15 @@ Action = @( @{ Execute = 'powershell' - Argument = @' --NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-3-1)\"" -'@ + Argument = '-NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-3-1)\""' } @{ Execute = 'powershell' - Argument = @' --NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-3-2)\"" -'@ + Argument = '-NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-3-2)\""' } @{ Execute = 'powershell' - Argument = @' --NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-3-3)\"" -'@ + Argument = '-NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-3-3)\""' } ) Settings = @{ diff --git a/test/definitions/scheduledtasks/tasks-1.json b/test/definitions/scheduledtasks/tasks-1.json index cb0003e..18a6508 100644 --- a/test/definitions/scheduledtasks/tasks-1.json +++ b/test/definitions/scheduledtasks/tasks-1.json @@ -1,166 +1,166 @@ [ { "TaskName": "MyTaskName1", - "Action": [ - { - "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-1-1)\\\"\"", - "Execute": "powershell" - }, - { - "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-1-2)\\\"\"", - "Execute": "powershell" - } - ], + "TaskPath": "\\MyTaskFolder\\", "Trigger": [ { "AtStartup": true }, { + "DaysInterval": 1, + "Daily": true, "At": { + "Day": 30, + "Second": 0, "Year": 1999, - "Hour": 17, "Minute": 30, - "Second": 0, - "Day": 30, + "Hour": 17, "Month": 11 - }, - "Daily": true, - "DaysInterval": 1 + } + } + ], + "Action": [ + { + "Execute": "powershell", + "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-1-1)\\\"\"" + }, + { + "Execute": "powershell", + "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-1-2)\\\"\"" } ], - "Settings": { - "DontStopIfGoingOnBatteries": true, - "Disable": false, - "AllowStartIfOnBatteries": true - }, "Principal": { - "UserId": "VssAdministrator", "LogonType": "S4U", + "UserId": "VssAdministrator", "RunLevel": "Highest" }, - "TaskPath": "\\MyTaskFolder\\" + "Settings": { + "Disable": false, + "DontStopIfGoingOnBatteries": true, + "AllowStartIfOnBatteries": true + } }, { "TaskName": "MyTaskName2", - "Action": [ - { - "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-2-1)\\\"\"", - "Execute": "powershell" - }, - { - "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-2-2)\\\"\"", - "Execute": "powershell" - } - ], + "TaskPath": "\\MyTaskFolder\\", "Trigger": [ { + "Once": true, "RepetitionInterval": { - "Minute": 0, + "Second": 0, "Hour": 12, - "Second": 0 + "Minute": 0 }, "At": { + "Day": 30, + "Second": 0, "Year": 1999, - "Hour": 14, "Minute": 0, - "Second": 0, - "Day": 30, + "Hour": 14, "Month": 11 }, - "Once": true, "RepetitionDuration": { "Days": 9999 } } ], - "Settings": { - "DontStopIfGoingOnBatteries": true, - "Disable": false, - "AllowStartIfOnBatteries": true - }, + "Action": [ + { + "Execute": "powershell", + "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-2-1)\\\"\"" + }, + { + "Execute": "powershell", + "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-2-2)\\\"\"" + } + ], "Principal": { - "UserId": "NT AUTHORITY\\SYSTEM", "LogonType": "S4U", + "UserId": "NT AUTHORITY\\SYSTEM", "RunLevel": "Limited" }, - "TaskPath": "\\MyTaskFolder\\" + "Settings": { + "Disable": false, + "DontStopIfGoingOnBatteries": true, + "AllowStartIfOnBatteries": true + } }, { "TaskName": "MyTaskName3", - "Action": [ - { - "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-3-1)\\\"\"", - "Execute": "powershell" - }, - { - "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-3-2)\\\"\"", - "Execute": "powershell" - }, - { - "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-3-3)\\\"\"", - "Execute": "powershell" - } - ], + "TaskPath": "\\MyTaskFolder\\", "Trigger": [ { + "DaysInterval": 1, + "Daily": true, "At": { + "Day": 30, + "Second": 0, "Year": 1999, - "Hour": 10, "Minute": 0, - "Second": 0, - "Day": 30, + "Hour": 10, "Month": 11 - }, - "Daily": true, - "DaysInterval": 1 + } }, { + "DaysInterval": 1, + "Daily": true, "At": { + "Day": 30, + "Second": 0, "Year": 1999, - "Hour": 14, "Minute": 0, - "Second": 0, - "Day": 30, + "Hour": 14, "Month": 11 - }, - "Daily": true, - "DaysInterval": 1 + } }, { + "DaysInterval": 1, + "Daily": true, "At": { + "Day": 30, + "Second": 0, "Year": 1999, - "Hour": 18, "Minute": 0, - "Second": 0, - "Day": 30, + "Hour": 18, "Month": 11 - }, - "Daily": true, - "DaysInterval": 1 + } }, { + "DaysInterval": 1, + "Daily": true, "At": { + "Day": 30, + "Second": 0, "Year": 1999, - "Hour": 22, "Minute": 0, - "Second": 0, - "Day": 30, + "Hour": 22, "Month": 11 - }, - "Daily": true, - "DaysInterval": 1 + } + } + ], + "Action": [ + { + "Execute": "powershell", + "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-3-1)\\\"\"" + }, + { + "Execute": "powershell", + "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-3-2)\\\"\"" + }, + { + "Execute": "powershell", + "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-3-3)\\\"\"" } ], - "Settings": { - "DontStopIfGoingOnBatteries": true, - "Disable": false, - "AllowStartIfOnBatteries": true - }, "Principal": { - "UserId": "VssAdministrator", "LogonType": "S4U", + "UserId": "VssAdministrator", "RunLevel": "Highest" }, - "TaskPath": "\\MyTaskFolder\\" + "Settings": { + "Disable": false, + "DontStopIfGoingOnBatteries": true, + "AllowStartIfOnBatteries": true + } } ] diff --git a/test/definitions/scheduledtasks/tasks-1.ps1 b/test/definitions/scheduledtasks/tasks-1.ps1 index 6bccdcd..00653a2 100644 --- a/test/definitions/scheduledtasks/tasks-1.ps1 +++ b/test/definitions/scheduledtasks/tasks-1.ps1 @@ -51,15 +51,11 @@ Action = @( @{ Execute = 'powershell' - Argument = @' --NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-1-1)\"" -'@ + Argument = '-NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-1-1)\""' } @{ Execute = 'powershell' - Argument = @' --NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-1-2)\"" -'@ + Argument = '-NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-1-2)\""' } ) Settings = @{ @@ -103,15 +99,11 @@ Action = @( @{ Execute = 'powershell' - Argument = @' --NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-2-1)\"" -'@ + Argument = '-NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-2-1)\""' } @{ Execute = 'powershell' - Argument = @' --NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-2-2)\"" -'@ + Argument = '-NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-2-2)\""' } ) Settings = @{ @@ -221,21 +213,15 @@ Action = @( @{ Execute = 'powershell' - Argument = @' --NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-3-1)\"" -'@ + Argument = '-NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-3-1)\""' } @{ Execute = 'powershell' - Argument = @' --NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-3-2)\"" -'@ + Argument = '-NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-3-2)\""' } @{ Execute = 'powershell' - Argument = @' --NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-3-3)\"" -'@ + Argument = '-NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-3-3)\""' } ) Settings = @{ diff --git a/test/definitions/scheduledtasks/tasks-2.json b/test/definitions/scheduledtasks/tasks-2.json index 04b5cc7..4481e2e 100644 --- a/test/definitions/scheduledtasks/tasks-2.json +++ b/test/definitions/scheduledtasks/tasks-2.json @@ -1,166 +1,166 @@ [ { "TaskName": "MyTaskName4", - "Action": [ - { - "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-4-1)\\\"\"", - "Execute": "powershell" - }, - { - "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-4-2)\\\"\"", - "Execute": "powershell" - } - ], + "TaskPath": "\\MyTaskFolder\\", "Trigger": [ { "AtStartup": true }, { + "DaysInterval": 1, + "Daily": true, "At": { + "Day": 30, + "Second": 0, "Year": 1999, - "Hour": 17, "Minute": 30, - "Second": 0, - "Day": 30, + "Hour": 17, "Month": 11 - }, - "Daily": true, - "DaysInterval": 1 + } + } + ], + "Action": [ + { + "Execute": "powershell", + "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-4-1)\\\"\"" + }, + { + "Execute": "powershell", + "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-4-2)\\\"\"" } ], - "Settings": { - "DontStopIfGoingOnBatteries": true, - "Disable": false, - "AllowStartIfOnBatteries": true - }, "Principal": { - "UserId": "VssAdministrator", "LogonType": "S4U", + "UserId": "VssAdministrator", "RunLevel": "Highest" }, - "TaskPath": "\\MyTaskFolder\\" + "Settings": { + "Disable": false, + "DontStopIfGoingOnBatteries": true, + "AllowStartIfOnBatteries": true + } }, { "TaskName": "MyTaskName5", - "Action": [ - { - "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-5-1)\\\"\"", - "Execute": "powershell" - }, - { - "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-5-2)\\\"\"", - "Execute": "powershell" - } - ], + "TaskPath": "\\MyTaskFolder\\", "Trigger": [ { + "Once": true, "RepetitionInterval": { - "Minute": 0, + "Second": 0, "Hour": 12, - "Second": 0 + "Minute": 0 }, "At": { + "Day": 30, + "Second": 0, "Year": 1999, - "Hour": 14, "Minute": 0, - "Second": 0, - "Day": 30, + "Hour": 14, "Month": 11 }, - "Once": true, "RepetitionDuration": { "Days": 9999 } } ], - "Settings": { - "DontStopIfGoingOnBatteries": true, - "Disable": false, - "AllowStartIfOnBatteries": true - }, + "Action": [ + { + "Execute": "powershell", + "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-5-1)\\\"\"" + }, + { + "Execute": "powershell", + "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-5-2)\\\"\"" + } + ], "Principal": { - "UserId": "NT AUTHORITY\\SYSTEM", "LogonType": "S4U", + "UserId": "NT AUTHORITY\\SYSTEM", "RunLevel": "Limited" }, - "TaskPath": "\\MyTaskFolder\\" + "Settings": { + "Disable": false, + "DontStopIfGoingOnBatteries": true, + "AllowStartIfOnBatteries": true + } }, { "TaskName": "MyTaskName6", - "Action": [ - { - "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-6-1)\\\"\"", - "Execute": "powershell" - }, - { - "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-6-2)\\\"\"", - "Execute": "powershell" - }, - { - "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-6-3)\\\"\"", - "Execute": "powershell" - } - ], + "TaskPath": "\\MyTaskFolder\\", "Trigger": [ { + "DaysInterval": 1, + "Daily": true, "At": { + "Day": 30, + "Second": 0, "Year": 1999, - "Hour": 10, "Minute": 0, - "Second": 0, - "Day": 30, + "Hour": 10, "Month": 11 - }, - "Daily": true, - "DaysInterval": 1 + } }, { + "DaysInterval": 1, + "Daily": true, "At": { + "Day": 30, + "Second": 0, "Year": 1999, - "Hour": 14, "Minute": 0, - "Second": 0, - "Day": 30, + "Hour": 14, "Month": 11 - }, - "Daily": true, - "DaysInterval": 1 + } }, { + "DaysInterval": 1, + "Daily": true, "At": { + "Day": 30, + "Second": 0, "Year": 1999, - "Hour": 18, "Minute": 0, - "Second": 0, - "Day": 30, + "Hour": 18, "Month": 11 - }, - "Daily": true, - "DaysInterval": 1 + } }, { + "DaysInterval": 1, + "Daily": true, "At": { + "Day": 30, + "Second": 0, "Year": 1999, - "Hour": 22, "Minute": 0, - "Second": 0, - "Day": 30, + "Hour": 22, "Month": 11 - }, - "Daily": true, - "DaysInterval": 1 + } + } + ], + "Action": [ + { + "Execute": "powershell", + "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-6-1)\\\"\"" + }, + { + "Execute": "powershell", + "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-6-2)\\\"\"" + }, + { + "Execute": "powershell", + "Argument": "-NonInteractive -NoProfile -NoLogo -Command \"New-Item \\\"$env:TEMP\\$(Get-Date -UFormat .%s-6-3)\\\"\"" } ], - "Settings": { - "DontStopIfGoingOnBatteries": true, - "Disable": false, - "AllowStartIfOnBatteries": true - }, "Principal": { - "UserId": "VssAdministrator", "LogonType": "S4U", + "UserId": "VssAdministrator", "RunLevel": "Highest" }, - "TaskPath": "\\MyTaskFolder\\" + "Settings": { + "Disable": false, + "DontStopIfGoingOnBatteries": true, + "AllowStartIfOnBatteries": true + } } ] diff --git a/test/definitions/scheduledtasks/tasks-2.ps1 b/test/definitions/scheduledtasks/tasks-2.ps1 index a4f38c2..e69a37a 100644 --- a/test/definitions/scheduledtasks/tasks-2.ps1 +++ b/test/definitions/scheduledtasks/tasks-2.ps1 @@ -51,15 +51,11 @@ Action = @( @{ Execute = 'powershell' - Argument = @' --NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-4-1)\"" -'@ + Argument = '-NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-4-1)\""' } @{ Execute = 'powershell' - Argument = @' --NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-4-2)\"" -'@ + Argument = '-NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-4-2)\""' } ) Settings = @{ @@ -103,15 +99,11 @@ Action = @( @{ Execute = 'powershell' - Argument = @' --NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-5-1)\"" -'@ + Argument = '-NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-5-1)\""' } @{ Execute = 'powershell' - Argument = @' --NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-5-2)\"" -'@ + Argument = '-NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-5-2)\""' } ) Settings = @{ @@ -221,21 +213,15 @@ Action = @( @{ Execute = 'powershell' - Argument = @' --NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-6-1)\"" -'@ + Argument = '-NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-6-1)\""' } @{ Execute = 'powershell' - Argument = @' --NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-6-2)\"" -'@ + Argument = '-NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-6-2)\""' } @{ Execute = 'powershell' - Argument = @' --NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-6-3)\"" -'@ + Argument = '-NonInteractive -NoProfile -NoLogo -Command "New-Item \"$env:TEMP\$(Get-Date -UFormat .%s-6-3)\""' } ) Settings = @{