I need help with a script
-
יום שני 27 פברואר 2012 19:48
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.
כל התגובות
-
יום שני 27 פברואר 2012 21:23
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
- הוצע כתשובה על-ידי Rich PrescottModerator יום שלישי 28 פברואר 2012 00:16
-
יום שני 27 פברואר 2012 23:25
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!- הוצע כתשובה על-ידי Rich PrescottModerator יום שלישי 28 פברואר 2012 00:16
- נערך על-ידי GastoneCanaliMicrosoft Community Contributor יום שלישי 28 פברואר 2012 08:34
- סומן כתשובה על-ידי rkassing יום שלישי 28 פברואר 2012 14:49
-
יום שלישי 28 פברואר 2012 16:43
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.
-
יום שלישי 28 פברואר 2012 17:13
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! -
יום שלישי 28 פברואר 2012 17:23What do I add to make it delay 1 sec per line.
-
יום שלישי 28 פברואר 2012 23:10
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
)
::endGastone 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!