Re: VBS Shutdown script loop not working

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




"Courtney Smith" <CourtneySmith@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:D85BDB59-4223-486E-9F93-82F5D57485B4@xxxxxxxxxxxxxxxx
I'm a newby, so please bear with me. I'm in the "find it online and modify
to
make it do what you want" stage of my scripting career. I want a script to
shutdown all the servers listed in a ServerList.txt file.

First I wrote a batch file using the shutdown command. It works, but it
only
does one at a time. This wouldn't be so bad if it didn't wait until the
server was shutdown before it returned to the script to get the next
server
in the list.

So I decided to use a script. I found and modified a shutdown server
script,
but it isn't looping. Now, I noticed if I change the script so the ACTION
is
to write to a file, it loops fine. But if the ACTION is to shutdown the
servers, it shuts down the first server in the list, then it is done.

Can anyone help? Here it is. Thank you in advance for taking a moment to
look at this. I appreciate greatly all the help I can get!

*********************
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInputFile = objFSO.OpenTextFile("C:\Shutdown
Scripts\ServerList.txt",
1, True)
Set objTextFile = objFSO.OpenTextFile("c:\Shutdown
Scripts\TabbedResults.tsv", 2, True)

Do Until objInputFile.AtEndOfStream
strComputer = Trim(objInputFile.ReadLine)
If (strComputer <> "") Then
Const Shutdown=1
Set objWMIService =
GetObject("winmgmts:{impersonationLevel=impersonate,(Shutdown)}\\" &
strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery ("SELECT * FROM
Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
ObjOperatingSystem.Win32Shutdown(Shutdown)
objTextFile.WriteLine strComputer
Next
End If
Loop
objInputFile.Close
objTextFile.Close
**************
--
Thank you!

Courtney

Your batch file solution is easily solved with a single line of code:
@echo off
for /F %%a in (servers.lst) do start /b "" shutdown -s -f \\%%a

This will eliminate the wait period.


.



Relevant Pages

  • Re: VBS Shutdown script loop not working
    ... I want a script to ... First I wrote a batch file using the shutdown command. ... server was shutdown before it returned to the script to get the next ...
    (microsoft.public.scripting.vbscript)
  • Re: Remote OS Shutdown with WMI problems
    ... 2003 server. ... This script will work if someone is logged into the server that is ... definitely receives and interprets the shutdown message however doesn't ... moves the mouse to cancel the screensaver. ...
    (microsoft.public.win32.programmer.wmi)
  • Re: Remote OS Shutdown with WMI problems
    ... 2003 server. ... This script will work if someone is logged into the server that is ... definitely receives and interprets the shutdown message however doesn't ... moves the mouse to cancel the screensaver. ...
    (microsoft.public.win32.programmer.wmi)
  • Re: Auto Logoff or forced sync of My Documents
    ... Here's a copy of the VB script I run as a scheduled task on my server, ... ErrorMessage "No shutdown method has been specified in the command line." ...
    (microsoft.public.windows.server.sbs)
  • Re: server checking script to save time
    ... I also have a flaky Microsoft Server 2003 cluster which i would LOVE ... leaving work on time if this script saves me time, ... for each strComputer in arrServers ... For Each objDisk in colDisks ...
    (microsoft.public.scripting.wsh)