3

Is there any way, how to schedule Windows tasks|jobs on all servers from central location (server)? Has Microsoft any solution for this? I prefer MS or Windows Server built-in functionalities before SW from third party...

Thanks

[edit]: Sorry for incomprehensibility. I know, that I can manage tasks through "Task Scheduler" on remote server or I can manage them using PowerShell, but that's not easy centralized management. Cmdlet "Get-ScheduledTask" don't have "server" parameter, so I need to connect individualy to every server, run for example cmdlet "Get-ScheduledTask", than run on every task on that server "Get-ScheduledTaskInfo", because cmdlet "Get-ScheduledTask" itself tells you nothing and this way collect data from all servers? And not to mention editing tasks. That's really not a simple script. My idea is, that I have for example "Task Scheduler", but with tasks from all specified servers. Or at least PowerShell cmdlets with better approach to this task. I thought, that managing scheduled tasks on all servers from one place isn't so uncommon so it should be implemented into Windows Server. Need to write quite complicated scripts on such a common and simple thing....

(btw.. I'm using Windows Server 2012)

So I'm asking, if I missed something, or I really need to write that (quite long) script if I don't want to buy some third party software.

HopelessN00b
  • 53,385
  • 32
  • 133
  • 208
devlin
  • 145
  • 1
  • 3
  • 12

5 Answers5

2

You can use Group Policy Preferences to create a scheduled task and deploy it via GPO. This is probably the quickest way to get what you're looking for.

If you're entitled to System Center licensing, you should also explore System Center Orchestrator.

edit: I was so surprised that there were 4 previous answers that didn't mention GPO as a possibility, that I wrote a blog post with a quick rundown of how to do this.

Esa Jokinen
  • 43,252
  • 2
  • 75
  • 122
MDMarra
  • 100,183
  • 32
  • 195
  • 326
1

It depends on what tasks you want to execute.

You can for example schedule a PowerShell command on one machine, which then in turn connects to other machines and executes powershell commands.

Edit:

After clarification from the OP, here's how you can execute the Command on a remote server from PS:

Invoke-Command -ComputerName MYCOMPUTERNAME -ScriptBlock {
        Get-ScheduledTask | Get-ScheduledTaskInfo | fl
}
MichelZ
  • 11,008
  • 4
  • 30
  • 58
1

By default, the Task Scheduler in Vista+ and Server 2008 R2+ will allow you to connect to a Task Scheduler on another computer.

enter image description here

You can also do so with PowerShell remoting (if you have an OS that supports those cmdlets), or via cmd.exe with WinRM or PSExec, if you want a fully scripted approach.

HopelessN00b
  • 53,385
  • 32
  • 133
  • 208
  • I need to have an overview, which tasks are scheduled on each server and I need to have an option to simply manage these tasks from one tool. I have around 30 servers, so connecting to each server separately through Task Scheduler GUI is really...... Yes, I know that I can use PowerShell and write a script which can do this, but I'm i little bit lazy, so I hoped that there is a tool for this :) – devlin Apr 04 '14 at 13:50
  • 1
    @devlin Well, that's not what you asked, is it? You asked about scheduling tasks remotely, not about *managing* scheduled tasks on remote servers. :) Asking for a tool to do that is a product recomendation, and off-topic, here... but you might want to look at [Task Scheduler Pro](http://www.liebsoft.com/Task_Scheduler_Pro/), or [VisualCron](http://www.visualcron.com/). You can do the same thing with PowerShell, actually.. but since you're lazy and don't want to write that up... well, there ya go. – HopelessN00b Apr 04 '14 at 13:54
  • I don't want to recommend software. I don't think, that this is off-topic. Sorry for incomprehensibility. I updated my question. – devlin Apr 04 '14 at 17:32
1

The PS cmdlets do seem to be lacking for managing scheduled tasks, but I think you're overestimating the complexity of reporting on tasks, or creating the same task across multiple servers.

The SCHTASKS exe is useful tool for managing tasks programatically:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb736357%28v=vs.85%29.aspx

# Inventory Report
foreach ($server in gc .\serverList.txt) {
    write-warning $server
    SCHTASKS.EXE /s $server /query /fo csv > tasks.csv
    $csv = Import-Csv .\tasks.csv
    $csv | where {$_.taskname.lastindexof("\") -eq 0 -OR $_.taskname -match "\\Legacy" }    # Ignore bultin OS tasks from MS
}

# Create task if missing
foreach ($server in gc .\serverList.txt) {
    write-warning $server
    SCHTASKS.EXE /s $server /query /fo csv > tasks.csv
    $csv = Import-Csv .\tasks.csv
    if ( $csv.taskname.contains("\TaskNameToFind") ) {
        "Job already present"
    } else {
        SCHTASKS.EXE /s $server /Create /SC MONTHLY /MO first /D SUN /TN TaxTime C:\windows\system32\calc.exe
    }
}

You could similarly remove the same tasks across multiple servers by using the first half of the IF condition in the second example with the /DELETE operator.

Clayton
  • 4,483
  • 16
  • 24
1

To give you another angle - this normally is done using special centralized software and one that can do that is microsoft system center operations manager.

http://www.systemcentercentral.com/opsmgr-forum-discussion-task-automation-with-opsmgr-rules-or-windows-scheduled-tasks/

has some discussion about this.

An example for an enterprise task scheduler you can find at http://www.jamsscheduler.com/ - the feature list may enlighten you on why those exist.

Although once things get complex there is much better 3rd party software. Not as SCOM is bad - but it is not specializd as enterprise scheduling software, the scheduling part of part of some management pack. Enterpise Schedulers can run distributed workflows with complex dependencies (first run script a on those machines, once that is done that script on machine b, then back to cleanup scriptson the first set while yet another machine does file uploads).

The advantage of SCOM and enterprise schedulers is control, central, especially with specialized toold. Automation turns complex fast and an operations team must be able to see what is going on.

TomTom
  • 50,857
  • 7
  • 52
  • 134