Vbscript / Files And Folders / File Type Report Scan
Scan machines for all files with the specified extension and report on the file paths and properties. Uses an input file to specify machine names to target.
Set objFSO = CreateObject("Scripting.FileSystemObject") fileExt = "msg" On Error Resume Next ''LOGGING logName = "File Scan Output.tsv" logFields = "Time" & vbTab & "Computer" & vbTab & " File Path " & vbTab & "File Size/KB" & vbTab & "Created" & vbTab & "Last Modified" & vbTab & "Last Accessed" 'Create log titles if file not present If objFSO.FileExists(logName) = 0 Then Set objLogFile = objFSO.OpenTextFile(logName, 8, True) objLogFile.WriteLine(logFields) Else 'Open log for writing (create if nonexistent) Set objLogFile = objFSO.OpenTextFile(logName, 8) End If inputFile = "servers.txt" If objFSO.FileExists(inputFile) Then targetServers = ListToArray(inputFile) For Each strCompName in targetServers objLogFile.WriteLine(Now() & vbTab & strCompName & vbTab & "Starting Server Scan") If NOT strCompName = "" Then scanComputer(strCompName) End If Next End If Wscript.Echo "Done" '****************************************** Function scanComputer(strComputer) 'On Error Resume Next Set objWMIService = GetObject("winmgmts:" & strComputer & " ootcimv2") Set colFiles = objWMIService.ExecQuery("Select * From CIM_DataFile Where Extension = '" & fileExt & "'") For Each objFile in colFiles
objLogFile.WriteLine (Now() & vbTab & strComputer & vbTab & objFile.Name & vbTab & objFile.FileSize/1024 & vbTab & WMIDate(objFile.CreationDate) & vbTab & WMIDate(objFile.LastModified) & vbTab & WMIDate(objFile.LastAccessed)) If Err.Number <> 0 Then objLogFile.WriteLine(Now() & vbTab & strComputer & vbTab & "Access Denied: " & strComputer & " " & Err.Description) Err.Clear End If Next
End Function '****************************************** 'ListToArray: Returns an array of strings as specified in a CR separated list file Function ListToArray(strPath)
'On Error Resume Next Set objFile = objFSO.OpenTextFile(strPath,1) Do Until objFile.AtEndOfStream user = Trim(objFile.Readline) If(strComp(user,"")/1 = 1) Then userString = userString & "%%" & user End If Loop 'Remove 1st comma 'userString = Right(userString, Len(userString)-2) objFile.Close ListToArray = Split(userString,"%%") If Err.Number <> 0 Then objLogFile.WriteLine(Now() & vbTab & "Error while converting list to array: " & strPath & Err.Description) Err.Clear End If End Function '****************************************** Function WMIDate(dtmInstallDate) WMIDate = CDate(Mid(dtmInstallDate, 7, 2) & "/" & _ Mid(dtmInstallDate, 5, 2) & "/" & Left(dtmInstallDate, 4) _ & " " & Mid (dtmInstallDate, 9, 2) & ":" & _ Mid(dtmInstallDate, 11, 2) & ":" & Mid(dtmInstallDate, _ 13, 2)) End Function Add Comment
Please note that a disclaimer applies to any code on this page.
|