locked
I need help with a script RRS feed

  • Question

  • I need a script that will restart a list of computers on a TXT or CSV file.  I need this to run on both XP and WIN 7.  Here is what I have so far:

    c:\windows\system32\shutdown -r -f -t 900 -c "Save documents computer is restarting."

    What I can't get is how to import the file and have to batch file read it. 

    If you need more information let me know.

    Thanks for your help.

    Monday, February 27, 2012 7:48 PM

Answers

  • This is a standard batch

    @echo off
    :: shutdown-from-list.cmd
    setlocal
    
    set Timeout=900
    set msg="Go home! It's late..."
    
    for /f "eol=;" %%c in (C:\admin\pclist.txt) do shutdown -r -f -t %Timeout% -c %msg% -m %%c
    ::end

    or a more evolute Fast Asynchronous Shutdown  ... you can shutdown 100 computers in 100 seconds and have some log

    @echo off
    ::
    :: asynchronous shutdown 
    :: shutdown only computer Alive (Alive = if there is a ping replay)
    :: Fast-async-shut.cmd
    ::
    :: by gastone canali
    setlocal
    set path=c:\admin;c:\admin\bin;%path%
    
    set filename=%~n0
    set logfile="c:\admin\log\_%filename%.txt"
    set appendLOG=^>^> %logfile% 2^>^&1
    
    set Timeout=900
    set msg="Go home! It's late..."
    
    for /f "eol=;" %%c in (C:\admin\pclist.txt) do call :_SHUT %%c
     
    goto :_END
    
    
    :_SHUT
    title=%1
    
    echo >%temp%\%1.cmd @echo off
    echo>>%temp%\%1.cmd title=%1
    echo>>%temp%\%1.cmd ping %1 -n 2^|find  "TTL=" ^>nul ^&^& (echo ALIVE ^&^& goto :_Shutdown)
    echo>>%temp%\%1.cmd goto :EOF
    echo>>%temp%\%1.cmd :_Shutdown
    echo>>%temp%\%1.cmd echo Alive  %1 - Shutdown!! 
    echo>>%temp%\%1.cmd shutdown -r -f -t %Timeout% -c %msg% -m %1
    echo>>%temp%\%1.cmd rem pause 
    echo>>%temp%\%1.cmd exit
    rem run shutdown batch
    start c:\windows\system32\cmd.exe /c "%temp%\%1.cmd"
    rem Wait 1 seconds
    ping 127.0.0.1 -n 1 1>nul  2>nul
    goto :EOF
    
    :_END
    
    ::end  Fast-async-shut.cmd


    Gastone Canali >http://www.armadillo.it

    Se alcuni post rispondono al tuo quesito (non necessariamente i miei), ricorda di contrassegnarli come risposta e non dimenticare di contrassegnare anche i post utili . GRAZIE!


    • Proposed as answer by Rich Prescott Tuesday, February 28, 2012 12:16 AM
    • Edited by GastoneCanali Tuesday, February 28, 2012 8:34 AM
    • Marked as answer by rkassing Tuesday, February 28, 2012 2:49 PM
    Monday, February 27, 2012 11:25 PM

All replies

  • Hi,

    try this code in Powershell

    $computers= get-content computer.txt
    foreach ($Computer in $Computers) {
        start-process c:\windows\system32\shutdown -Argumentlist "/r /f /t 900 /c "Save documents computer is restarting." /m $computer" 
    }

    The file computer.txt should containe one compuername (FQDN) per line.


    regards Thomas Paetzold visit my blog on: http://sus42.wordpress.com

    • Proposed as answer by Rich Prescott Tuesday, February 28, 2012 12:16 AM
    Monday, February 27, 2012 9:23 PM
  • This is a standard batch

    @echo off
    :: shutdown-from-list.cmd
    setlocal
    
    set Timeout=900
    set msg="Go home! It's late..."
    
    for /f "eol=;" %%c in (C:\admin\pclist.txt) do shutdown -r -f -t %Timeout% -c %msg% -m %%c
    ::end

    or a more evolute Fast Asynchronous Shutdown  ... you can shutdown 100 computers in 100 seconds and have some log

    @echo off
    ::
    :: asynchronous shutdown 
    :: shutdown only computer Alive (Alive = if there is a ping replay)
    :: Fast-async-shut.cmd
    ::
    :: by gastone canali
    setlocal
    set path=c:\admin;c:\admin\bin;%path%
    
    set filename=%~n0
    set logfile="c:\admin\log\_%filename%.txt"
    set appendLOG=^>^> %logfile% 2^>^&1
    
    set Timeout=900
    set msg="Go home! It's late..."
    
    for /f "eol=;" %%c in (C:\admin\pclist.txt) do call :_SHUT %%c
     
    goto :_END
    
    
    :_SHUT
    title=%1
    
    echo >%temp%\%1.cmd @echo off
    echo>>%temp%\%1.cmd title=%1
    echo>>%temp%\%1.cmd ping %1 -n 2^|find  "TTL=" ^>nul ^&^& (echo ALIVE ^&^& goto :_Shutdown)
    echo>>%temp%\%1.cmd goto :EOF
    echo>>%temp%\%1.cmd :_Shutdown
    echo>>%temp%\%1.cmd echo Alive  %1 - Shutdown!! 
    echo>>%temp%\%1.cmd shutdown -r -f -t %Timeout% -c %msg% -m %1
    echo>>%temp%\%1.cmd rem pause 
    echo>>%temp%\%1.cmd exit
    rem run shutdown batch
    start c:\windows\system32\cmd.exe /c "%temp%\%1.cmd"
    rem Wait 1 seconds
    ping 127.0.0.1 -n 1 1>nul  2>nul
    goto :EOF
    
    :_END
    
    ::end  Fast-async-shut.cmd


    Gastone Canali >http://www.armadillo.it

    Se alcuni post rispondono al tuo quesito (non necessariamente i miei), ricorda di contrassegnarli come risposta e non dimenticare di contrassegnare anche i post utili . GRAZIE!


    • Proposed as answer by Rich Prescott Tuesday, February 28, 2012 12:16 AM
    • Edited by GastoneCanali Tuesday, February 28, 2012 8:34 AM
    • Marked as answer by rkassing Tuesday, February 28, 2012 2:49 PM
    Monday, February 27, 2012 11:25 PM
  • thank you for your help.

    I am using the top script and it works great.  What do I add to make it delay 1 sec per line.

    Tuesday, February 28, 2012 4:43 PM
  • Perfect.


    Gastone Canali >http://www.armadillo.it

    Se alcuni post rispondono al tuo quesito (non necessariamente i miei), ricorda di contrassegnarli come risposta e non dimenticare di contrassegnare anche i post utili . GRAZIE!

    Tuesday, February 28, 2012 5:13 PM
  • What do I add to make it delay 1 sec per line.
    Tuesday, February 28, 2012 5:23 PM
  • ok  

    @echo off
    :: shutdown-from-list.cmd
    setlocal

    set Timeout=900
    set msg="Go home! It's late..."
    set wait=2

    for
    /f "eol=;" %%c in (C:\admin\pclist.txt) do (
    shutdown -r -f -t %Timeout% -c %msg% -m %%c
    ping -n %wait% 127.0.0.1 1>nul 2>nul
    )
    ::
    end



    Gastone Canali >http://www.armadillo.it

    Se alcuni post rispondono al tuo quesito (non necessariamente i miei), ricorda di contrassegnarli come risposta e non dimenticare di contrassegnare anche i post utili . GRAZIE!

    Tuesday, February 28, 2012 11:10 PM