Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete Schedul Task from multiple servers 1

Status
Not open for further replies.

Junbron

Technical User
Mar 5, 2012
15
NZ
heres a script to delete an specific task in a machine..
can anyone please be able to help to add a script for me to be able to delete that specific Task from multiple servers..
I have a list of the server in txt file..

Thanks


Dim objShell As Object

Set objShell = CreateObject("Wscript.Shell")
objShell.Exec ("schtasks /delete /tn ""MyTaskName""")
Set objShell = Nothing
 
[tt]schtasks[/tt] has a /system switch to specify on what machine the command should execute. Use the File System Object to open you server text file, read the contents one server at a time, and plug the servername into the command. Here's a small example

list.txt
Code:
serverA
serverB
serverC

deleteTask.vbs
Code:
[COLOR=#CC0000]set objFSO = CreateObject("Scripting.FileSystemObject")[/color]
set objShell = CreateObject("WScript.Shell")

[COLOR=#CC0000]set objStream = objFSO.OpenTextFile("C:\list.txt", 1)[/color]
do while not objStream.AtEndOfStream
   [COLOR=#729FCF]strServer = trim(objStream.ReadLine)[/color]
   [COLOR=#73D216]strCommand = "schtasks /delete /s " & strServer " /tn ""MyTaskName"""[/color]
   objShell.exec strCommand
loop
msgbox "done"

-Geates

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top