+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
Scripts Thread, Shutdown Computers in 4 Classrooms Script / Prog in Coding and Web Development; Knocked this up quickly - some may find it handy. [ Unzip it to a single dir from a hard ...
  1. #1

    mattx's Avatar
    Join Date
    Jan 2007
    Posts
    9,240
    Thank Post
    1,058
    Thanked 1,068 Times in 625 Posts
    Rep Power
    740

    Shutdown Computers in 4 Classrooms Script / Prog

    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.
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by mattx; 27th June 2008 at 09:08 PM.

  2. #2

    mattx's Avatar
    Join Date
    Jan 2007
    Posts
    9,240
    Thank Post
    1,058
    Thanked 1,068 Times in 625 Posts
    Rep Power
    740
    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 ]

  3. #3

    Join Date
    Jan 2007
    Posts
    41
    Thank Post
    2
    Thanked 1 Time in 1 Post
    Rep Power
    0

    A suggested improvement

    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.

  4. #4

    EduTech's Avatar
    Join Date
    Aug 2007
    Location
    Reading
    Posts
    5,063
    Thank Post
    160
    Thanked 920 Times in 723 Posts
    Blog Entries
    3
    Rep Power
    272
    Added to Wiki

    PsShutdown Tool - EduGeek.net Wiki

    James.

  5. #5
    mullet_man's Avatar
    Join Date
    Oct 2005
    Location
    Oldham
    Posts
    726
    Thank Post
    34
    Thanked 46 Times in 45 Posts
    Rep Power
    26
    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

  6. #6

    Join Date
    Jan 2007
    Posts
    41
    Thank Post
    2
    Thanked 1 Time in 1 Post
    Rep Power
    0

    herewith the script we use

    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

  7. Thanks to jrubinstein from:

    FN-GM (29th June 2008)

  8. #7

    RabbieBurns's Avatar
    Join Date
    Apr 2008
    Location
    Sydney
    Posts
    5,521
    Thank Post
    1,333
    Thanked 469 Times in 306 Posts
    Blog Entries
    6
    Rep Power
    199
    whats the difference between psshutdown and the regular windows shutdown.exe ?

  9. #8

    mattx's Avatar
    Join Date
    Jan 2007
    Posts
    9,240
    Thank Post
    1,058
    Thanked 1,068 Times in 625 Posts
    Rep Power
    740
    Quote Originally Posted by RabbieBurns View Post
    whats the difference between psshutdown and the regular windows shutdown.exe ?
    PsShutdown is more powerful in regards to the options and functions it has.

  10. #9
    monkeyx's Avatar
    Join Date
    Nov 2006
    Posts
    364
    Thank Post
    8
    Thanked 52 Times in 41 Posts
    Rep Power
    25
    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.

  11. #10

    john's Avatar
    Join Date
    Sep 2005
    Location
    London
    Posts
    10,611
    Thank Post
    1,496
    Thanked 1,051 Times in 920 Posts
    Rep Power
    303
    Quote Originally Posted by monkeyx View Post
    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

  12. #11
    Galway's Avatar
    Join Date
    Jun 2007
    Location
    West Yorkshire
    Posts
    1,343
    Thank Post
    9
    Thanked 305 Times in 214 Posts
    Rep Power
    100
    Id be interested in that monkey.

  13. #12
    monkeyx's Avatar
    Join Date
    Nov 2006
    Posts
    364
    Thank Post
    8
    Thanked 52 Times in 41 Posts
    Rep Power
    25
    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.

    Code:
    ' 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 tim@monkeyx.net
    
    '***************************************************************************************
    ' 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

  14. #13
    Silverman's Avatar
    Join Date
    Oct 2007
    Location
    Worksop, Nottinghamshire
    Posts
    50
    Thank Post
    15
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Some nice scripts.

    The one to change the local admin passwords sounds good too monkey if you could post that. Could come in useful.

  15. #14
    HMCTech's Avatar
    Join Date
    Apr 2008
    Posts
    618
    Thank Post
    37
    Thanked 48 Times in 35 Posts
    Rep Power
    22
    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?

  16. #15

    powdarrmonkey's Avatar
    Join Date
    Feb 2008
    Location
    Alcester, Warwickshire
    Posts
    4,859
    Thank Post
    412
    Thanked 777 Times in 650 Posts
    Rep Power
    182
    @AlexPilot: PM me, I have a swap for you

SHARE:
+ Post New Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Script to shutdown computers.
    By FN-GM in forum Scripts
    Replies: 18
    Last Post: 17th November 2008, 03:43 PM
  2. Script to add computers to AD like RIS
    By box_l in forum Scripts
    Replies: 2
    Last Post: 4th June 2008, 08:34 PM
  3. Shutdown batch script stalls if 1 PC is shut down
    By PrimaryTech in forum Scripts
    Replies: 8
    Last Post: 7th July 2007, 06:04 PM
  4. Replies: 3
    Last Post: 23rd March 2007, 09:36 AM
  5. Replies: 18
    Last Post: 14th October 2005, 09:28 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •