Cazale Posted November 20, 2015 Posted November 20, 2015 Afternoon! I'm trying to implement a batch file to remotely shut down a group of PCs, but have hit a small snag. I'm running a command (from the domain controller) along the lines of: shutdown.exe /s /f /m \\[computer_name] /t 120 /c "Warning: PC will shutdown in 2 minutes" Basically that command * the number of PCs I want to shut down in a batch file. It works well, unless the PC is already turned off. If the PC is already off it sits for a minute or so before timing out with the error message "The entered computer name is not valid or remote shutdown is not supported on the target computer" and then moves on to the next line of the bat file. If one PC isn't turned on this isn't too much of an issue, but if 30 PCs are turned off it takes 30 minutes (30 * 1 minute timeouts) to run a script that should run instantly. Anyone know a funky way to suppress this error as the bat file runs through the shutdown commands?
Sephiroth Posted November 20, 2015 Posted November 20, 2015 If doing this for domain joined machines, the way I do this is to add the script, without the "/m" switch, as a scheduled task in group policy. Simple solution and hasn't missed a beat yet. 1
browolf Posted November 20, 2015 Posted November 20, 2015 (edited) you want to figure out if the computer is on before you try to shut it down; A faster check than the shutdown timeout. my script does del loggedin.txt for /f %%a in ('type comp.log') do ( for /f %%b in ('net view ^| find "\\%%a" /I ') do ( if exist %%b\c$ ( pslist %%b | find "explorer" /I && echo %%b >> loggedin.txt if errorlevel 1 down %%b /P /Q))) Edited November 20, 2015 by browolf 1
3s-gtech Posted November 20, 2015 Posted November 20, 2015 You can also run this via GPP, so that it doesn't try to run over the network with the /m switch, it just runs locally on each PC using Task Scheduler. Quite a slick way of doing it. 2
Cazale Posted November 20, 2015 Author Posted November 20, 2015 Thanks for all the replies. Doing this through a group policy (and having it run locally) certainly make sense, especially as it is an end of day thing, so will always run at the same time. Thanks again!
just_david Posted November 27, 2015 Posted November 27, 2015 This ended up being the solution to my (nigh identicle) issue too, thanks
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now