0

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:

HKLM\Software\Microsoft\Windows NT\CurrentVersion\Schedule\Taskcache\Tasks
HKLM\Software\Microsoft\Windows NT\CurrentVersion\Schedule\Taskcache\Tree

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

0

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:\Windows\System32\Tasks\TestTask'  | Out-GridView
Get-ChildItem -Path 'C:\Windows\System32\Tasks'

Export-ScheduledTask 'TestTask' | 
out-file '\\TargetServer\c$\public\TestTask.xml'

Invoke-Command -ComputerName 'TargetServer' -ScriptBlock {
    Register-ScheduledTask -Xml (Get-Content 'C:\Users\public\TestTask.xml' | out-string) -TaskName 'TestTask'
}

Just use a list of servers in a loop the registration

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.