Code Script .co.uk

Home | Scripts | Tutorials | Disclaimer | Sitemap | Contact

   File Type Report Scan
 

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
Your Name:
Comment:




Please note that a disclaimer applies to any code on this page.
 
   Actions
  Go Back
  Bookmark
  Print Page


   Menu
 
- Links
- Reference
- Script Editors
- Tutorials
- Vbscript
     - Active Directory
     - Exchange
     - Files And Folders
          - Auto Copy Files From Cdrom
          - Backup My Documents
          - Cleanup Filenames
          - Create Remote File Share
          - File Properties
          - File Server Report
          - File Type Report Scan
          - Find And Replace Filename Text
          - Find And Replace Text In Files
          - Folder Size Scanner
          - Rename Files Find And Remove Text
          - Rename Files Find And Replace Text
          - Replace Folder Ntfs Security Permissions
          - Simple File Report
          - Sort And Move Files To Folders
          - Windows File Locations
     - General
     - Ms Office
     - Operating System
     - Processes And Services
     - Text Processing
     - User Interaction
     - Web Servers