Solved

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

Posted on 2008-06-25
7
508 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:radar365
  • 5
  • 2
7 Comments
 

Author Comment

by:radar365
ID: 21868667
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.
0
 

Author Comment

by:radar365
ID: 21869334
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.
0
 

Author Comment

by:radar365
ID: 21869344
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.
0
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
LVL 26

Expert Comment

by:farhankazi
ID: 21872477
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

0
 

Author Comment

by:radar365
ID: 21874299
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%
0
 
LVL 26

Accepted Solution

by:
farhankazi earned 500 total points
ID: 21874344
You need to add following line inside IF condition block.
ECHO PROCESSING: %%c >>%OutputFile%
You can also add Date and Time like:
ECHO Date: %DATE%  Time: %TIME% >>%OutputFile%

Like:
:: 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 (
                ECHO PROCESSING: %%c>>%OutputFile%
		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

0
 

Author Closing Comment

by:radar365
ID: 31470701
You are a GURU of scripting.  Thank you. : )-
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Bizarre hard disk problem 15 133
Backup DHCP Server 8 116
creating a random password in batch 4 26
Scan Network and Export Reg value to single file 2 18
Many of us need to configure DHCP server(s) in their environment. We can do that simply via DHCP console on server or using MMC snap-in on each computer with Administrative Tools installed in a network. But what if we have to configure many DHCP ser…
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question