Script Center > Gallery > Desktop Management > Log Out, Reboot, or Shut Down Multiple Computers
TechNet Script Center logo

Welcome to the TechNet Script Center Gallery!

Each contribution is licensed to you under a License Agreement by its owner, not Microsoft. Microsoft does not guarantee the contribution or purport to grant rights to it.

Log Out, Reboot, or Shut Down Multiple Computers

(Community)
Rate it:
 
 
 
 
 
Script Code
VBScript
'This script logs off, shuts down, reboots, or powers off (depending on the selection) 
'the computers listed in the Server array
'The user excuting the script must have administrative rights to the target machines
'Target computers running Windows Firewall need to follow the information in KB article _
'875605 on how to allow remote administration
'
'Submitted by Bruce Walton

'Prompt the user for the desired action
msg="Please select one of the following:" & vbcrlf & "0 - Log off" & vbcrlf & _
    "1 - Shutdown" & vbcrlf & "2 - Reboot" & vbcrlf & "8 - Power Off"

flag=inputbox(msg)
'Make sure the section is appropriate
if flag<>0 and flag<>1 and flag<>2 and flag<>8 then
    msgbox "Incorrect selection"
    wscript.quit
end if

'The computers to send the command to.  This list can be changed to allow for user input
Servers=array("computer1", "computer2", "computer3")

for x=lbound(servers) to ubound(servers)
    'Create the WMI object
    for each OS in getobject ("winmgmts:{(Shutdown)}//" & servers(x) & _
        "/root/cimv2").InstancesOf("Win32_OperatingSystem")
        'Change the WMI security to allow for shut downs, reboots, etc
        set Security = OS.Security_
        set PrivObj = Security.Privileges
        PrivObj.Add(18)
    
        'Send the command
        RetVal = OS.Win32ShutDown(flag,0)
    next
    if RetVal = 0 then
        wscript.echo "Shutdown " & servers(x)
    else
        wscript.echo "Unable to shutdown " & servers(x)
    end if
next
Platforms
Windows Server 2008 R2 No
Windows Server 2008 No
Windows Server 2003 No
Windows 7 No
Windows Vista No
Windows XP No
Windows 2000 No
For online peer support, join The Official Scripting Guys Forum! To provide feedback or report bugs in sample scripts, please start a new discussion on the Discussions tab for this script.
Disclaimer The sample scripts are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.
Be the first to create a discussion.