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?



enter image description here










share|improve this question


























    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?



    enter image description here










    share|improve this question
























      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?



      enter image description here










      share|improve this question













      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?



      enter image description here







      windows powershell active-directory group-policy scheduled-tasks






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 24 at 3:57









      vulcan raven

      371212




      371212






















          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






          share|improve this answer





















            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "3"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            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

























            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






            share|improve this answer

























              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






              share|improve this answer























                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






                share|improve this answer












                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







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 24 at 8:27









                postanote

                83513




                83513






























                    draft saved

                    draft discarded




















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    Paul Cézanne

                    UIScrollView CustomStickyHeader Resize height generates problems when scroll is too fast

                    Angular material date-picker (MatDatepicker) auto completes the date on focus out