Home

Google
 

How do I Remotely Shutdown all Domain Computers -VBscript

If you every need to shutdown all you domain computers due to a expected power outage, security breach etc. then this Vbscript should help:
On Error Resume Next

Set objNet = CreateObject(”wscript.network”)
strCurrentPC = objNet.ComputerName

‘The following section will connect to any Active Directory domain

Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject(”ADODB.Connection”)
Set objCommand = CreateObject(”ADODB.Command”)
objConnection.Provider = “ADsDSOObject”
objConnection.Open “Active Directory Provider”
Set objCommand.ActiveConnection = objConnection
Set objDSE = GetObject(”LDAP://RootDSE”)
strDomain = objDSE.Get(”DefaultNamingContext”)
objCommand.CommandText = “SELECT Name, Location FROM ‘LDAP://” & strDomain & “‘ ” & “WHERE objectClass=’computer’”
objCommand.Properties(”Page Size”) = 1000
objCommand.Properties(”Timeout”) = 30
objCommand.Properties(”Searchscope”) = ADS_SCOPE_SUBTREE
objCommand.Properties(”Cache Results”) = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strPCName = objRecordSet.Fields(”Name”).Value
If strPCName <> strCurrentPC then
set colOS = getobject(”winmgmts:{impersonationlevel=impersonate,(shutdown)}//” & strPCName).instancesof(”win32_operatingsystem”)
For each objOS in colOS
objOS.win32shutdown(1)
Next
End if
objRecordSet.MoveNext
Loop

======================================

This script can be easily modified to include other shutdown options which include reboots and log offs. Reference the Microsoft MSDN site: http://msdn2.microsoft.com/en-us/library/aa394058.aspx for more details on the win32shutdown class.



powered by FreeFind