VBS: Check for file existence on a set of remote comuters.

Home Forums Scripting Windows Script Host VBS: Check for file existence on a set of remote comuters.

This topic contains 0 replies, has 1 voice, and was last updated by Avatar guyt 15 years, 5 months ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • Avatar
    guyt
    Member
    #98229
    Code:
    ‘********************************************************************
    ‘* Author: Guy Teverovsky
    ‘*
    ‘* The script enumerates the computer objects in a given OU,
    ‘* checks whether a computer is reachable over the network,
    ‘* and if yes, verifies the existence of a given file on the
    ‘* remote computer.
    ‘* Can be used for checking “flag” files like c:NotWorm or
    ‘* dll versions. I used it to verify that users got a specific update
    ‘* installed.
    ‘*
    ‘********************************************************************

    strOUDN = “OU=Workstations,OU=Clients,DC=test,DC=net”

    Set objRootDSE = GetObject(”LDAP://RootDSE”)
    strClientsPath = “LDAP://” & strOUDN
    Set objClientsContainer = GetObject(strClientsPath)
    objClientsContainer.filter=array(”computer”)

    ‘The file we want to check
    strSearchFile = “c$Program FilesTestTest.exe”

    For Each objClient In objClientsContainer
    arClient= split(objClient.Name,”=”)
    strClient = arClient(1)
    If IsPingable(strClient) Then
    Set objFSO = CreateObject(”Scripting.FileSystemObject”)
    strSearchFileUNC = “\” & strClient & “” & strSearchFile
    If objFSO.FileExists(strSearchFileUNC) Then
    strSearchFileVer = objFSO.GetFileVersion(strSearchFileUNC)
    If strSearchFileVer <> “” Then
    Wscript.Echo(strSearchFileVer)
    End If
    Else
    WScript.Echo(”Computer ” & strClient & ” does not have the file in question”)
    End If
    Else
    WScript.Echo(”The client is not reachable…”)
    End If

    Next

    ‘********************************************************************
    ‘* Function IsPingable(strHost)
    ‘*
    ‘* Returns True or False based on the output from ping.exe
    ‘********************************************************************
    Function IsPingable(strHost)
    Set objShell = WScript.CreateObject(”WScript.Shell”)
    Set objExecObject = objShell.Exec(”cmd /c ping.exe -n 3 -w 1000 ” & strHost)
    Do While Not objExecObject.StdOut.AtEndOfStream
    strText = objExecObject.StdOut.ReadLine()
    If Instr(strText, “Reply”) > 0 Then
    ‘Wscript.Echo “Reply received.”
    IsPingable = True
    Exit Do
    End If
    Loop
    If (IsPingable <> True) Then
    IsPingable = False
    End If
    End Function

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.