ASKER
ASKER
If LCase(Right(Wscript.FullName, 11)) = "wscript.exe" Then
strPath = Wscript.ScriptFullName
strCommand = "%comspec% /c cscript """ & strPath & """"
Set objShell = CreateObject("Wscript.Shell")
objShell.Run(strCommand), 1, True
Wscript.Quit
End If
strLogFile = "Time_On_Servers.csv"
arrOtherServers = Array("XPPC1","XPPC2")
For Each strComputer In arrOtherServers
strQuery = strQuery & " OR Name='" & strComputer & "'"
Next
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strLogFile) = True Then objFSO.DeleteFile strLogFile, True
Const intForReading = 1
Set objShell = CreateObject("WScript.Shell")
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.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
objCommand.CommandText = "SELECT name FROM 'LDAP://" & strDNSDomain & "' WHERE operatingSystem='*server*'" & strQuery
Set objRecordSet = objCommand.Execute
Set objDictionary = CreateObject("Scripting.Dictionary")
While Not objRecordSet.EOF
strComputer = objRecordSet.Fields("name").Value
If Ping(strComputer) = True Then
WScript.Echo "Querying " & strComputer
strCommand = "cmd /c net time \\" & strComputer & " >> """ & strLogFile & """"
objShell.Run strCommand, 0, True
Else
WScript.Echo strComputer & " offline"
strCommand = "cmd /c echo " & strComputer & ",Offline >> """ & strLogFile & """"
objShell.Run strCommand, 0, True
End If
objRecordSet.MoveNext
Wend
objRecordSet.Close
Set objRecordSet = Nothing
' Clean up output file
Set objLogfile = objFSO.OpenTextFile(strLogFile, intForReading, False)
strContents = Replace(objLogfile.ReadAll, VbCrLf & "The command completed successfully." & VbCrLf & VbCrLf, "")
strContents = Replace(Replace(strContents, "Current time at \\", ""), " is ", ",")
objLogfile.Close
Set objLogfile = objFSO.CreateTextFile(strLogFile, True)
objLogfile.Write strContents
objLogFile.Close
Set objLogFile = Nothing
MsgBox "Finished. Please see " & strLogFile
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
Perl is a high-level, general-purpose, interpreted, dynamic programming languages with over 25 years of development. Perl 5 runs on over 100 platforms from portables to mainframes and is suitable for both rapid prototyping and large-scale development projects. Perl gained widespread popularity as a Common Gateway Interface (CGI) scripting language, in part due to its regular expression and string parsing abilities. In addition to CGI, Perl is used for graphics programming, system administration, network programming, finance, bioinformatics, and other applications.
TRUSTED BY
net time /QUERYSNTP