Question : Best way to search desktops for a file?

Hi all,

I wanted to know what was the best way to search the C:\ drives of all our desktops for a particular file and feed this into a report or .txt file?  I'm trying to make sure that .pst files aren't being created locally on users machines so want to scan to make sure they don't exist.  Ideally I'd like a report that gives something like:

Machine Name      File found
NET1                           Archive.pst
NET2                           None found
NET3                           Personal Folders.pst

Does anyone know of an easy way of doing this?

Answer : Best way to search desktops for a file?

use SEARCH_PATH to set the root folder from which to dig the files
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
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
Random Solutions  
 
programming4us programming4us