On Error Resume Next
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
'--- change the DN to where you want to start your search ---
objCommand.CommandText = _
"<LDAP://ou=workstations,ou=corp,dc=domain,dc=com>;" & _
"(objectCategory=computer);distinguishedName,name; subtree"
Set objRecordSet = objCommand.Execute
While Not objRecordSet.EOF
RestartComputer objRecordSet.Fields("Name")
objRecordSet.MoveNext
Wend
objConnection.Close
Sub RestartComputer(strComputer)
set objShell = CreateObject("WScript.Shell")
objShell.Run "shutdown -s -t 0 -f -m \\" & strComputer
End Sub
ASKER
ASKER
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
objCommand.CommandText = _
"Select Name, Location from 'LDAP://ou=Computers,ou=HWM,dc=client,dc=local' " _
& "Where objectClass='computer'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
SET objRecordSet = objCommand.EXECUTE
objRecordSet.MoveFirst
DO Until objRecordSet.EOF
Wscript.Echo "Computer Name: " & objRecordSet.Fields("Name").Value
Wscript.Echo "Location: " & objRecordSet.Fields("Location").Value
objRecordSet.MoveNext
LOOP
'On Error Resume Next
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
'--- change the DN to where you want to start your search ---
objCommand.CommandText = _
"<LDAP://ou=IT Computers,ou=it,dc=domain,dc=com>;" & _
"(objectCategory=computer);distinguishedName,name;subtree"
Set objRecordSet = objCommand.Execute
While Not objRecordSet.EOF
If Ping(objRecordSet.Fields("Name")) = True Then
WScript.Echo "Reading last boot up time from " & objRecordSet.Fields("Name")
WScript.Echo objRecordSet.Fields("Name") & ": " & GetBootUpTime(objRecordSet.Fields("Name"))
Else
WScript.Echo objRecordset.Fields("Name") & " is offline"
End If
objRecordSet.MoveNext
Wend
objConnection.Close
WScript.Echo "Done"
' GetBootUpTime function
Function GetBootUpTime( strComputer )
Dim objItem
Dim objWMIService, colItems
Dim strBootUpTime
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select LastBootUpTime from Win32_OperatingSystem",,48)
For Each objItem in colItems
strBootUpTime = Left(objItem.LastBootUpTime, InStr(objItem.LastBootUpTime, ".") -1)
Next
GetBootUpTime = strBootUpTime
End Function
Function Ping(strComputer)
Dim objShell, boolCode
Set objShell = CreateObject("WScript.Shell")
boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
If boolCode = 0 Then
Ping = True
Else
Ping = False
End If
End Function
ASKER
ASKER
VBScript (Visual Basic Scripting Edition) is an interpreted scripting language developed by Microsoft that is modeled on Visual Basic, but with some important differences. VBScript is commonly used for automating administrative and other tasks in Windows operating systems (by means of the Windows Script Host) and for server-side scripting in ASP web applications. It is also used for client-side scripting in Internet Explorer, specifically in intranet web applications.
TRUSTED BY
cscript GetLastBootTime.vbs
and see what you get. I haven't tested it yet.
Regards,
Rob.
Open in new window