In this post you will see how powerful powershell is in combination with external applications like SCHTASKS.exe.
First you have to create a CSV file like this:
Name Server1.domain.local Server2.domain.local |
The following one-liner imports the CSV file and creates a task on every server which is saved in the CSV file:
# Create a scheduled task on all the servers in *.csv import-csv ".\*.csv" | % { schtasks /create /S $_.Name /SC DAILY /TN "Task_Name" /TR "program_or_script" /ST time /RU account}
The next one-liner imports the CSV file and will modify a scheduled task on every server which is saved in the CSV file:
# Change a scheduled task on all the servers in *.csv import-csv ".\*.csv" | % { schtasks /change /TN "Task_Name" /S $_.Name /TR "program_or_script" /ST 23:05 /RU System }
The last one-liner imports the CSV file and will delete a scheduled task on every server which is saved in the CSV file:
# Delete a scheduled task on all the servers in *.csv import-csv ".\*.csv" | % { schtasks /delete /tn "Task_Name" /f /s $_.Name }
More info about how to use SCHTASKS.exe can be found here: KB814596