mattx Posted June 27, 2008 Posted June 27, 2008 (edited) Knocked this up quickly - some may find it handy. [ Unzip it to a single dir from a hard drive root otherwise PsShutdown may not work correctly ] It uses the PsShutdown Tool alongside a set of .txt files labelled classroom1.txt to classroom4.txt All you have to do is fill the relevant .txt files in with the computer names of your computers, one line per entry [ or IP addresses ] Fire off the psshutdown classroom.exe & choose your method. The Normal button will shut PCs down in the relevant txt files within 15 seconds but will show a cancel button just in case someone is sitting at it !! The Forced button will force all applications to close and will shutdown the computer with NO option to cancel. Again there is a 15 second countdown. Any problems, let me know. Some may find it handy if they have more than one room with PCs in. It's best run on a PC with Admin Rights / current credentials over the domain.classroom shutdown.zip Edited June 27, 2008 by mattx
mattx Posted June 27, 2008 Author Posted June 27, 2008 I've changed the script slightly so it now includes a timeout. I've set it to 5 seconds as I noticed when it was going through large .txt files it sometimes took a while to go down the list - [ this of course depends on your network !! ] Any problems let me know.... [ Download from the first post as removed the old .zip and replaced it with the new one ]
jrubinstein Posted June 29, 2008 Posted June 29, 2008 I've run psshutdown for a while at our school (roughly 550 computers). Initially I built a list of all computers out of the SMS database and run shutdown on that list. The problem was that psshutdown keeps trying for quite a while to connect to a machine which may already be shut down. To get round 550 machines therefore took too long, some were still waiting for the shutdown command the next morning. Instead I ran a short ping on each machine (2 pings not 4) and depending on successful connection wrote the machine name into a text file. Then ran psshutdown on that file. Unfortunately I can't reach the school at the moment (problems at an intermediate server) but I'll try to post the script itself tomorrow.
EduTech Posted June 29, 2008 Posted June 29, 2008 Added to Wiki PsShutdown Tool - EduGeek.net Wiki James.
mullet_man Posted June 29, 2008 Posted June 29, 2008 Looks good, cheers. We use a psshutdown script in one big file, was looking to move to per room based script as it can take a long time to get through all machines. This will come in handy to shut down machines on demand cheers
jrubinstein Posted June 29, 2008 Posted June 29, 2008 Hope this is useful to someone. We keep the psshutdown exe in the same folder as this. I limit the size of each text file to 25 machines and the script automatically starts the shutdown process on each file as it finishes building it. ' VBScript File Option Explicit Dim OdbcDSN Dim objFSO, objFolder, objShell, objFile,objFSO1 Dim strDirectory, strFile dim g dim strIP 'This section sets up the text files and their folder Dim connect, sql, resultSet Set objFSO1 = CreateObject("Scripting.FileSystemObject") Set objFSO = CreateObject("Scripting.FileSystemObject") strDirectory = "c:\adminscripts" If objFSO.FolderExists(strDirectory) Then Set objFolder = objFSO.GetFolder(strDirectory) Else Set objFolder = objFSO.CreateFolder(strDirectory) End If 'next the variables dim machinecount machinecount = 0 dim overcount overcount = 0 dim filecount filecount = 0 'this section builds the list from the sms database - it relies on the computer 'having a system dsn connection named sms-connection. 'if you are using a text file or some other list you'd have to put your own 'listbuilding section in here. OdbcDSN = "DSN=sms_connection" Set connect = CreateObject("ADODB.Connection") connect.Open OdbcDSN sql="SELECT * from jr_machine_details" Set resultSet = connect.Execute(sql) 'next go through the result set. On Error Resume Next resultSet.MoveFirst Do While Not resultSet.eof 'the next four lines check variables in the list 'we have a series of different scripts for different times of day if len(resultset("machine_name")) > 1 then if left(resultset("Server_workstation"),11) = "workstation" then if resultset("shutdown_6_30") = "True" then if ucase(left(resultset("machine_name"),3)) = ucase("ila") then 'now we begin to build the text file strfile = "5_30_" & filecount & ".txt" 'if we haven't got a file then we need to create one. if machinecount = 0 then ' first check if file exists, if not create it If objFSO.FileExists(strFile) Then Else Set objFile = objFSO.CreateTextFile(strFile) objFile.Close set g = objFSO1.OpenTextFile (strfile,2) End If else set g = objFSO1.OpenTextFile (strfile,2) end if dim ipaddress ipaddress = resultset("IP_Address") 'given the ip address we will use the pingreply function to check that 'the computer is on line currently PingReply(ipaddress) if strIP = "Yes" then g.writeline resultset("machine_name") machinecount = machinecount + 1 overcount = overcount + 1 else end if 'at this point I set the script to start the psshutdown process on the file 'if the no of machines in the file has reached 25 if machinecount = 25 then machinecount = 0 'the closeit function uses the file to close the machines listed closeit (filecount) filecount = filecount + 1 end if End if end if end if end if resultSet.MoveNext Loop 'we need a final closeit to deal with the final text file which 'has not reached 25 machines. closeit (filecount) resultSet.Close connect.Close set g = nothing wscript.echo ("Done " & overcount & " records dealt with") Function Closeit(limit) Dim oShell Set oShell = CreateObject( "WScript.Shell" ) oShell.Run "psshutdown /accepteula -s -f -n 180 @5_30_" & limit & ".txt" Set oShell = Nothing end function 'This is a straight copy of a function taken from the internet - I can't remember 'exactly where - sorry Function PingReply(strPingIT) dim wshShell Set wshShell = CreateObject("WScript.Shell") Dim oWshExec, strPingResults Dim oRegEx, match, matches 'RegEx pattern from Bill Stewart Set oRegEx = New RegExp oRegEx.Pattern = " [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}: " 'Nod to Steve Cathersalc 'ping twice with 1 second timeout. Set oWshExec= wshShell.Exec("ping -n 2 -w 20 " & strPingIT) 'No need to loop or sleep or use oWshExec.status 'becuase can't proceed until StdOut completes Set Matches = oRegEx.Execute(oWshExec.StdOut.Readall) ' Execute search. If Matches.count = 1 Then 'couuld use oWshExec.ExitCode PingReply = True For Each Match in Matches ' Iterate Matches collection. 'strIP = trim(replace(Match.Value,":","")) 'Cleanup string located strIP = "Yes" Next Else strIP = "No" PingReply = False End If set oWshExec = Nothing set oRegEx = Nothing End Function 1
RabbieBurns Posted June 29, 2008 Posted June 29, 2008 whats the difference between psshutdown and the regular windows shutdown.exe ?
mattx Posted June 29, 2008 Author Posted June 29, 2008 whats the difference between psshutdown and the regular windows shutdown.exe ? PsShutdown is more powerful in regards to the options and functions it has.
Guest monkeyx Posted June 29, 2008 Posted June 29, 2008 I have written a script that shuts down every computer in an AD OU, if anyone is interested let me know and will post on here.
john Posted June 29, 2008 Posted June 29, 2008 I have written a script that shuts down every computer in an AD OU, if anyone is interested let me know and will post on here. Always useful
Guest monkeyx Posted June 30, 2008 Posted June 30, 2008 Here is the script that we run to shutdown an OU. It is basic and could be modded to use psshutdown, or even take the OU as an argument. We just have a script per room to keep things simple. The script was written as part of the training program to learn vbscript and ADSI for the school technicians. It is not shown a reference script for technical excellence, but the idea that you can run something against each machine in an OU is a cool one at least I have another version that we use to change all passwords for a local admin on the machines, when pupils need to logon as full admin as part of their course. (Anyone interested in that please let me know) Any problems with code example below please let me know. ' Shutdown All computers in OU ' You a freee to use this script as you wish, as long as you leave this header in place. ' Comments/Suggestions to [email protected] '*************************************************************************************** ' Create Reference to Wshell object for running command line programs '*************************************************************************************** Set WSHShell = WScript.CreateObject("WScript.Shell") '*************************************************************************************** ' Create Reference to OU to enumertate '*************************************************************************************** strOU = "ou=Room,ou=English,ou=Departments,ou=Managed Devices" ' e.g. Enter your own OU here '*************************************************************************************** ' Create Reference to OU Domain '*************************************************************************************** strDomain = "somedomain.local" ' you will need enter yor own domain here shutdownMessage="""End of day power down. Please save your work to prevent data loss""" '*************************************************************************************** ' Connect to Domain using default Naming Contect '*************************************************************************************** set objRootDSE = GetObject("LDAP://" & strDomain & "/RootDSE") set objParent = GetObject("LDAP://" & strOU & "," & objRootDSE.Get("defaultNamingContext")) '*************************************************************************************** ' Enumerate All Computer Objects in selected OU '*************************************************************************************** objParent.Filter = Array("computer") for each objUser in objParent '*************************************************************************************** ' run command prompt options /c closes after run 1,True shows command 0,True Hides command '************************************************************************************** ' Wscript.Echo "Will now try and Shutdown " & objUser.Get("Name") On Error Resume Next ShellRun = WSHShell.Run ("cmd /c shutdown /s /m \\" & objUser.Get("Name") & " /t: 300 /c " & shutdownMessage,0,True ) next
Silverman Posted July 1, 2008 Posted July 1, 2008 Some nice scripts. The one to change the local admin passwords sounds good too monkey if you could post that. Could come in useful.
HMCTech Posted September 8, 2008 Posted September 8, 2008 I am trying to find a way to shut down a room of PC's automatically at a certain time, then power them on again at a certain time the following morning. Does anyone have any advice?
powdarrmonkey Posted September 8, 2008 Posted September 8, 2008 @AlexPilot: PM me, I have a swap for you
pallen Posted September 8, 2008 Posted September 8, 2008 Run the shutdown scripts as a schedule task. You would need WOL to turn the computers back on in the morning(if shutdown overnight). If you have seperated the rooms out, you can run them at different times depending if you have night classes etc running. I used to use Lanview to start the machines up in the morning.
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