Thursday, September 14, 2017

Batch Script - Scheduled Task to Multiple PC's

Use the following to push out scheduled task to a list of PC's.

(Note: you need full domain admin privileges and admin sharing must be enabled on the clients)

1. Create a Scheduled task on your PC and export it as an xml file
NOTE: You could use basic 'schtasks' commands but using export/import xml is best as it is able to add all scheduling options and also overwrites existing task without prompt
2. Create a list of PC names on the network you want to reboot and put them into a text file
3. Create a batch file from the text below and put it into the same directory as the text file of PC's
4. Change the variables in the script and run it


@ECHO ON
::
SET sourcexmlfile=C:\Users\***\reboot.xml
SET destxmlfile=\\%%a\C$\Temp\reboot.xml
SET clientlist=reboot.txt
SET taskname=reboot
::
For /f "tokens=*" %%a in (%clientlist%) Do (
copy %sourcexmlfile% %destxmlfile%
psexec \\%%a schtasks.exe /create /tn %taskname% /RU system /xml %destxmlfile% /f
)


keywords:
microsoft task scheduler reboot multiple tasks batch file cmd automated list files scripting script




No comments:

Post a Comment