const SEARCH_PATH = "c:\temp"
const OUTPUT_FILE = "c:\temp\output.csv"
const SEARCH_EXT = "log"
const MACHINES_LIST = "meirpc"
Set fso = CreateObject("Scripting.FileSystemObject")
set objLogFile = fso.CreateTextFile(OUTPUT_FILE,2)
objLogFile.WriteLine "MachineName,FileName"
for each strComputer in Split(MACHINES_LIST, ",")
GetFiles strComputer, SEARCH_PATH, SEARCH_EXT
next
objLogFile.Close
sub GetFiles(strComputer,strFolderName,extension)
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colSubfolders = objWMIService.ExecQuery _
("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _
& "Where AssocClass = Win32_Subdirectory " _
& "ResultRole = PartComponent")
arrFolderPath = Split(strFolderName, "\")
strNewPath = ""
For i = 1 to Ubound(arrFolderPath)
strNewPath = strNewPath & "\\" & arrFolderPath(i)
Next
strPath = strNewPath & "\\"
Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_DataFile where Path = '" & strPath & "' and Extension='" + extension + "'")
For Each objFile in colFiles
objLogFile.WriteLine strComputer & "," & objFile.Name
Next
For Each objFolder in colSubfolders
GetSubFolders objWMIService,strComputer,strFolderName, extension
Next
end sub
Sub GetSubFolders(objWMIService,strComputer,strFolderName,extension)
Set colSubfolders2 = objWMIService.ExecQuery _
("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _
& "Where AssocClass = Win32_Subdirectory " _
& "ResultRole = PartComponent")
For Each objFolder2 in colSubfolders2
strFolderName = objFolder2.Name
arrFolderPath = Split(strFolderName, "\")
strNewPath = ""
For i = 1 to Ubound(arrFolderPath)
strNewPath = strNewPath & "\\" & arrFolderPath(i)
Next
strPath = strNewPath & "\\"
Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_DataFile where Path = '" & strPath & "' and Extension='" + extension + "'")
For Each objFile in colFiles
objLogFile.WriteLine strComputer & "," & objFile.Name
Next
GetSubFolders objWMIService,strComputer,strFolderName,extension
Next
End Sub
|