How to automate registration of a scheduled task through GPO using PowerShell?
up vote
0
down vote
favorite
I can manually run the following cmdlet on 10 nodes in AD to register a scheduled task:
Register-ScheduledTask `
-TaskName "MyTask" `
-Action $inlinePowershellScript `
-Trigger $myTaskTrigger `
-Principal $myTaskPrincipal
I was looking at the ways to automate it on AD level (preferably without leveraging WinRM..)
According to this article and the list of available GroupPolicy cmdlets, it seems like the only way to configure GPO (using PowerShell cmdlets) is by using Set-GPRegistryValue and Set-GPPrefRegistryValue cmdlets.
It seems like following registry keys are available for Scheduled Task:
HKLMSoftwareMicrosoftWindows NTCurrentVersionScheduleTaskcacheTasks
HKLMSoftwareMicrosoftWindows NTCurrentVersionScheduleTaskcacheTree
Given these details, is there a way to perform GPME's computer configuration -> Preferences -> Control Panel Settings -> Scheduled Tasks -> New -> Scheduled Tasks action automatically using $inlinePowershellScript, $myTaskTrigger and $myTaskPrincipal?

windows powershell active-directory group-policy scheduled-tasks
add a comment |
up vote
0
down vote
favorite
I can manually run the following cmdlet on 10 nodes in AD to register a scheduled task:
Register-ScheduledTask `
-TaskName "MyTask" `
-Action $inlinePowershellScript `
-Trigger $myTaskTrigger `
-Principal $myTaskPrincipal
I was looking at the ways to automate it on AD level (preferably without leveraging WinRM..)
According to this article and the list of available GroupPolicy cmdlets, it seems like the only way to configure GPO (using PowerShell cmdlets) is by using Set-GPRegistryValue and Set-GPPrefRegistryValue cmdlets.
It seems like following registry keys are available for Scheduled Task:
HKLMSoftwareMicrosoftWindows NTCurrentVersionScheduleTaskcacheTasks
HKLMSoftwareMicrosoftWindows NTCurrentVersionScheduleTaskcacheTree
Given these details, is there a way to perform GPME's computer configuration -> Preferences -> Control Panel Settings -> Scheduled Tasks -> New -> Scheduled Tasks action automatically using $inlinePowershellScript, $myTaskTrigger and $myTaskPrincipal?

windows powershell active-directory group-policy scheduled-tasks
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I can manually run the following cmdlet on 10 nodes in AD to register a scheduled task:
Register-ScheduledTask `
-TaskName "MyTask" `
-Action $inlinePowershellScript `
-Trigger $myTaskTrigger `
-Principal $myTaskPrincipal
I was looking at the ways to automate it on AD level (preferably without leveraging WinRM..)
According to this article and the list of available GroupPolicy cmdlets, it seems like the only way to configure GPO (using PowerShell cmdlets) is by using Set-GPRegistryValue and Set-GPPrefRegistryValue cmdlets.
It seems like following registry keys are available for Scheduled Task:
HKLMSoftwareMicrosoftWindows NTCurrentVersionScheduleTaskcacheTasks
HKLMSoftwareMicrosoftWindows NTCurrentVersionScheduleTaskcacheTree
Given these details, is there a way to perform GPME's computer configuration -> Preferences -> Control Panel Settings -> Scheduled Tasks -> New -> Scheduled Tasks action automatically using $inlinePowershellScript, $myTaskTrigger and $myTaskPrincipal?

windows powershell active-directory group-policy scheduled-tasks
I can manually run the following cmdlet on 10 nodes in AD to register a scheduled task:
Register-ScheduledTask `
-TaskName "MyTask" `
-Action $inlinePowershellScript `
-Trigger $myTaskTrigger `
-Principal $myTaskPrincipal
I was looking at the ways to automate it on AD level (preferably without leveraging WinRM..)
According to this article and the list of available GroupPolicy cmdlets, it seems like the only way to configure GPO (using PowerShell cmdlets) is by using Set-GPRegistryValue and Set-GPPrefRegistryValue cmdlets.
It seems like following registry keys are available for Scheduled Task:
HKLMSoftwareMicrosoftWindows NTCurrentVersionScheduleTaskcacheTasks
HKLMSoftwareMicrosoftWindows NTCurrentVersionScheduleTaskcacheTree
Given these details, is there a way to perform GPME's computer configuration -> Preferences -> Control Panel Settings -> Scheduled Tasks -> New -> Scheduled Tasks action automatically using $inlinePowershellScript, $myTaskTrigger and $myTaskPrincipal?

windows powershell active-directory group-policy scheduled-tasks
windows powershell active-directory group-policy scheduled-tasks
asked Nov 24 at 3:57
vulcan raven
371212
371212
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
You are over complicating this.
Schedule tasks are just xml files. create a task manually, export it and import it to other servers using the scheduled Task cmdlets.
Get-Command -Name '*scheduled*' | ft -a
CommandType Name Version Source
----------- ---- ------- ------
Function Disable-ScheduledTask 1.0.0.0 ScheduledTasks
Function Enable-ScheduledTask 1.0.0.0 ScheduledTasks
Function Export-ScheduledTask 1.0.0.0 ScheduledTasks
Function Get-ClusteredScheduledTask 1.0.0.0 ScheduledTasks
Function Get-ScheduledTask 1.0.0.0 ScheduledTasks
Function Get-ScheduledTaskInfo 1.0.0.0 ScheduledTasks
...
Example:
# Create your task
$A = New-ScheduledTaskAction –Execute 'powershell' -Argument 'Hello, from task scheduler'
$T = New-ScheduledTaskTrigger -Weekly -WeeksInterval 1 -DaysOfWeek Monday,Tuesday,Wednesday,Thursday,Friday -At 8am
$S = New-ScheduledTaskSettingsSet
$D = New-ScheduledTask -Action $A -Trigger $T -Settings $S
$Task = Register-ScheduledTask 'TestTask' -InputObject $D
# View the created task XML
Get-Content -Path 'C:WindowsSystem32TasksTestTask' | Out-GridView
Get-ChildItem -Path 'C:WindowsSystem32Tasks'
Export-ScheduledTask 'TestTask' |
out-file '\TargetServerc$publicTestTask.xml'
Invoke-Command -ComputerName 'TargetServer' -ScriptBlock {
Register-ScheduledTask -Xml (Get-Content 'C:UserspublicTestTask.xml' | out-string) -TaskName 'TestTask'
}
Just use a list of servers in a loop the registration
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
You are over complicating this.
Schedule tasks are just xml files. create a task manually, export it and import it to other servers using the scheduled Task cmdlets.
Get-Command -Name '*scheduled*' | ft -a
CommandType Name Version Source
----------- ---- ------- ------
Function Disable-ScheduledTask 1.0.0.0 ScheduledTasks
Function Enable-ScheduledTask 1.0.0.0 ScheduledTasks
Function Export-ScheduledTask 1.0.0.0 ScheduledTasks
Function Get-ClusteredScheduledTask 1.0.0.0 ScheduledTasks
Function Get-ScheduledTask 1.0.0.0 ScheduledTasks
Function Get-ScheduledTaskInfo 1.0.0.0 ScheduledTasks
...
Example:
# Create your task
$A = New-ScheduledTaskAction –Execute 'powershell' -Argument 'Hello, from task scheduler'
$T = New-ScheduledTaskTrigger -Weekly -WeeksInterval 1 -DaysOfWeek Monday,Tuesday,Wednesday,Thursday,Friday -At 8am
$S = New-ScheduledTaskSettingsSet
$D = New-ScheduledTask -Action $A -Trigger $T -Settings $S
$Task = Register-ScheduledTask 'TestTask' -InputObject $D
# View the created task XML
Get-Content -Path 'C:WindowsSystem32TasksTestTask' | Out-GridView
Get-ChildItem -Path 'C:WindowsSystem32Tasks'
Export-ScheduledTask 'TestTask' |
out-file '\TargetServerc$publicTestTask.xml'
Invoke-Command -ComputerName 'TargetServer' -ScriptBlock {
Register-ScheduledTask -Xml (Get-Content 'C:UserspublicTestTask.xml' | out-string) -TaskName 'TestTask'
}
Just use a list of servers in a loop the registration
add a comment |
up vote
0
down vote
You are over complicating this.
Schedule tasks are just xml files. create a task manually, export it and import it to other servers using the scheduled Task cmdlets.
Get-Command -Name '*scheduled*' | ft -a
CommandType Name Version Source
----------- ---- ------- ------
Function Disable-ScheduledTask 1.0.0.0 ScheduledTasks
Function Enable-ScheduledTask 1.0.0.0 ScheduledTasks
Function Export-ScheduledTask 1.0.0.0 ScheduledTasks
Function Get-ClusteredScheduledTask 1.0.0.0 ScheduledTasks
Function Get-ScheduledTask 1.0.0.0 ScheduledTasks
Function Get-ScheduledTaskInfo 1.0.0.0 ScheduledTasks
...
Example:
# Create your task
$A = New-ScheduledTaskAction –Execute 'powershell' -Argument 'Hello, from task scheduler'
$T = New-ScheduledTaskTrigger -Weekly -WeeksInterval 1 -DaysOfWeek Monday,Tuesday,Wednesday,Thursday,Friday -At 8am
$S = New-ScheduledTaskSettingsSet
$D = New-ScheduledTask -Action $A -Trigger $T -Settings $S
$Task = Register-ScheduledTask 'TestTask' -InputObject $D
# View the created task XML
Get-Content -Path 'C:WindowsSystem32TasksTestTask' | Out-GridView
Get-ChildItem -Path 'C:WindowsSystem32Tasks'
Export-ScheduledTask 'TestTask' |
out-file '\TargetServerc$publicTestTask.xml'
Invoke-Command -ComputerName 'TargetServer' -ScriptBlock {
Register-ScheduledTask -Xml (Get-Content 'C:UserspublicTestTask.xml' | out-string) -TaskName 'TestTask'
}
Just use a list of servers in a loop the registration
add a comment |
up vote
0
down vote
up vote
0
down vote
You are over complicating this.
Schedule tasks are just xml files. create a task manually, export it and import it to other servers using the scheduled Task cmdlets.
Get-Command -Name '*scheduled*' | ft -a
CommandType Name Version Source
----------- ---- ------- ------
Function Disable-ScheduledTask 1.0.0.0 ScheduledTasks
Function Enable-ScheduledTask 1.0.0.0 ScheduledTasks
Function Export-ScheduledTask 1.0.0.0 ScheduledTasks
Function Get-ClusteredScheduledTask 1.0.0.0 ScheduledTasks
Function Get-ScheduledTask 1.0.0.0 ScheduledTasks
Function Get-ScheduledTaskInfo 1.0.0.0 ScheduledTasks
...
Example:
# Create your task
$A = New-ScheduledTaskAction –Execute 'powershell' -Argument 'Hello, from task scheduler'
$T = New-ScheduledTaskTrigger -Weekly -WeeksInterval 1 -DaysOfWeek Monday,Tuesday,Wednesday,Thursday,Friday -At 8am
$S = New-ScheduledTaskSettingsSet
$D = New-ScheduledTask -Action $A -Trigger $T -Settings $S
$Task = Register-ScheduledTask 'TestTask' -InputObject $D
# View the created task XML
Get-Content -Path 'C:WindowsSystem32TasksTestTask' | Out-GridView
Get-ChildItem -Path 'C:WindowsSystem32Tasks'
Export-ScheduledTask 'TestTask' |
out-file '\TargetServerc$publicTestTask.xml'
Invoke-Command -ComputerName 'TargetServer' -ScriptBlock {
Register-ScheduledTask -Xml (Get-Content 'C:UserspublicTestTask.xml' | out-string) -TaskName 'TestTask'
}
Just use a list of servers in a loop the registration
You are over complicating this.
Schedule tasks are just xml files. create a task manually, export it and import it to other servers using the scheduled Task cmdlets.
Get-Command -Name '*scheduled*' | ft -a
CommandType Name Version Source
----------- ---- ------- ------
Function Disable-ScheduledTask 1.0.0.0 ScheduledTasks
Function Enable-ScheduledTask 1.0.0.0 ScheduledTasks
Function Export-ScheduledTask 1.0.0.0 ScheduledTasks
Function Get-ClusteredScheduledTask 1.0.0.0 ScheduledTasks
Function Get-ScheduledTask 1.0.0.0 ScheduledTasks
Function Get-ScheduledTaskInfo 1.0.0.0 ScheduledTasks
...
Example:
# Create your task
$A = New-ScheduledTaskAction –Execute 'powershell' -Argument 'Hello, from task scheduler'
$T = New-ScheduledTaskTrigger -Weekly -WeeksInterval 1 -DaysOfWeek Monday,Tuesday,Wednesday,Thursday,Friday -At 8am
$S = New-ScheduledTaskSettingsSet
$D = New-ScheduledTask -Action $A -Trigger $T -Settings $S
$Task = Register-ScheduledTask 'TestTask' -InputObject $D
# View the created task XML
Get-Content -Path 'C:WindowsSystem32TasksTestTask' | Out-GridView
Get-ChildItem -Path 'C:WindowsSystem32Tasks'
Export-ScheduledTask 'TestTask' |
out-file '\TargetServerc$publicTestTask.xml'
Invoke-Command -ComputerName 'TargetServer' -ScriptBlock {
Register-ScheduledTask -Xml (Get-Content 'C:UserspublicTestTask.xml' | out-string) -TaskName 'TestTask'
}
Just use a list of servers in a loop the registration
answered Nov 24 at 8:27
postanote
83513
83513
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1377941%2fhow-to-automate-registration-of-a-scheduled-task-through-gpo-using-powershell%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown