Déploiement automatique de tâches planifiées

Fermé
Freekill - 17 oct. 2008 à 11:39
 Pierre JOUBERT - 22 oct. 2008 à 08:47
Bonjour,


Je pose rapidement la situation, je suis informaticien dans une grande entreprise ou je m'occupe d'environ 500 PC.

J'aimerais activer un nettoyage de disque et une défragmentation automatique de mes postes une fois par semaine le mercredi entre midi et deux.

J'ai donc créé deux tâches planifiés par les commandes suivantes :

* Nettoyage automatique => AT 12:30 /Every:ME cleanmgr /sagerun:1

* Défragmentation automatique => AT 13:00 /Every:ME defrag c: -f

Les deux commandes crées bien deux tâches planifiées sans problème qui se lance le mercredi entre midi et deux.

Il faut donc désormais que je déploie ces deux commandes sur l'ensemble de mon parc.

Le souci étant que je ne peux pas le mettre dans un .bat qui se lance au démarrage parce qu'il me recréé à chaque fois les deux tâches planifiées.

Est ce que quelqu'un a une idée de comment je peux m'y prendre ? ( GPO, scripts ... )


Cordialement.

1 réponse

Pierre JOUBERT
22 oct. 2008 à 08:47
tu trouveras ci dessous trois exemples de code( pour tes scripts VBS) faisant la liste, la suppression et l'ajout d'une tache planifiée... n'hesites pas àa demander des précisions pour les personnaliser si tu en as besoin.


Deleting All Scheduled Tasks


Deletes all the scheduled tasks on a computer. Note: WMI can only delete scheduled tasks created with the Win32_ScheduledJob class or the At.exe utility. It cannot delete tasks created using the Task Scheduler.

Code Snippet

strComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colScheduledTasks = objWMIService.ExecQuery _ ("Select * from Win32_ScheduledJob")For Each objTask in colScheduledTasks intJobID = objTask.JobID Set objInstance = objWMIService.Get _ ("Win32_ScheduledJob.JobID=" & intJobID) objInstance.DeleteNext






Deleting a Scheduled Task


Deletes the scheduled task with the JobID of 1.

Code Snippet

strComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set objInstance = objWMIService.Get("Win32_ScheduledJob.JobID=1")err = objInstance.DeleteWscript.Echo err







Enumerating Scheduled Tasks


Enumerates all the scheduled tasks on a computer. Note: WMI can only enumerate scheduled tasks created with the Win32_ScheduledJob class or the At.exe utility. It cannot enumerate tasks created using the Task Scheduler.

Code Snippet

strComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colScheduledJobs = objWMIService.ExecQuery _ ("Select * from Win32_ScheduledJob")For Each objJob in colScheduledJobs Wscript.Echo "Caption: " & objJob.Caption Wscript.Echo "Command: " & objJob.Command Wscript.Echo "Days Of Month: " & objJob.DaysOfMonth Wscript.Echo "Days Of Week: " & objJob.DaysOfWeek Wscript.Echo "Description: " & objJob.Description Wscript.Echo "Elapsed Time: " & objJob.ElapsedTime Wscript.Echo "Install Date: " & objJob.InstallDate Wscript.Echo "Interact with Desktop: " & objJob.InteractWithDesktop Wscript.Echo "Job ID: " & objJob.JobID Wscript.Echo "Job Status: " & objJob.JobStatus Wscript.Echo "Name: " & objJob.Name Wscript.Echo "Notify: " & objJob.Notify Wscript.Echo "Owner: " & objJob.Owner Wscript.Echo "Priority: " & objJob.Priority Wscript.Echo "Run Repeatedly: " & objJob.RunRepeatedly Wscript.Echo "Start Time: " & objJob.StartTime Wscript.Echo "Status: " & objJob.Status Wscript.Echo "Time Submitted: " & objJob.TimeSubmitted Wscript.Echo "Until Time: " & objJob.UntilTimeNext







Scheduling a Task


Schedules Notepad to run at 12:30 PM every Monday, Wednesday, and Friday.

Code Snippet

strComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set objNewJob = objWMIService.Get("Win32_ScheduledJob")errJobCreated = objNewJob.Create _ ("Notepad.exe", "********123000.000000-420", _ True , 1 OR 4 OR 16, , , JobID) Wscript.Echo errJobCreated






Ce dernier illustrant l'opération que tu cherche à effectuer.

il te suffit de remplacer notepad par l'exe que tu cherche à lancer, puis de remplacer l'heure afin de la positionner sur celle de ton choix, et de lancer ce script sur tes postes via la GMPC...





cordialement,



PierrE.
0