Link to home
Start Free TrialLog in
Avatar of radar365
radar365Flag for United States of America

asked on

I need to configure scheduled tasks service to auto and then start the service on 50 + servers

I need to configure scheduled tasks service to auto and then start the service on 50 + servers.  I am using psservice and a for loop to cycle throught the servers.  Attached is what I have so far.  Thanks.




Service.txt
Error.txt
Avatar of radar365
radar365
Flag of United States of America image

ASKER

I am also trying to get a log of each server and weather there was an error or it completed successfully for each server.  This way I can keep track of which servers I will nedd to go back and look at.
I believe I have the first script all jacked up.  I have tested this from 1 server resetting services on the other and it works but the function to set to the service to auto or disabled does not seem to be working for me.  Here is what I have for the psservice commnads:

psservice.exe \\mmtg1fnlp013 setconfig Scheduler start-auto  >>"%MyLogFile%"
psservice.exe \\mmtg1fnlp013 start schedule             >>"%MyLogFile%"

The service gets started and stopped, now I  beliave that I just need to get the startup type to set correctly and add a for loop.  Thanks for your assistance as I am still learning the poes with mass scripting.  Guess you need to make sure the comand will work on 1 first before you go creating for loops and all that... I got the cart ahead of the horse.
By the way my log file for this shows the following:

Usage: psservice.exe [\\Computer [-u Username [-p Password]]] setconfig <svc> <start-type>
Sets the start type of the specified service where start-type
is one of auto, demand and disabled.

I believe I have the syntax set correctly.
Check following batch script if this helps!

:: BATCH SCRIPT START 
@ECHO OFF
SETLOCAL EnableDelayedExpansion
SET InputFile=srvlst.txt
SET OutputFile=DisableStatus.txt
 
IF NOT EXIST "%InputFile%" ECHO "%InputFile%" file does not exist. &GOTO :EndScript
FOR %%R IN ("%InputFile%") DO IF %%~zR EQU 0 ECHO "%InputFile%" file is empty. &GOTO :EndScript
IF EXIST "%OutputFile%" DEL /F /Q "%OutputFile%"
 
FOR /F %%c IN ('TYPE "%InputFile%"') DO (
        ECHO Processing: %%c
        PING -n 1 -w 1000 %%c|Find /I "TTL" >NUL
        IF NOT ERRORLEVEL 1 (
                SC \\%%c config "SentryII" start= auto >>%OutputFile%
				SC \\%%c START "SentryII" >>%OutputFile%
        )ELSE (ECHO Unable to connect %%c: system may be offline.))
 
ECHO. &ECHO Script complete. Check "%OutputFile%" file.
:EndScript
ENDLOCAL
EXIT /B 0
:: BATCH SCRIPT END

Open in new window

This is great and it works!!!  One last thing how would I also add the server name to the log so that I know which server if failed on if there was a failure?. Much Thanks.

SC \\%%c START "SentryII" >>%OutputFile%
ASKER CERTIFIED SOLUTION
Avatar of Farhan Kazi
Farhan Kazi
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You are a GURU of scripting.  Thank you. : )-