Windows::Inventory::Report files of particular extension
For desired file extensions this script will report the filename and file size for all machines listed in input file.
'==========================================================================
' Script to search for files with listed extensions
'==========================================================================
Option Explicit
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Const PATH_TO_INPUT = "in.txt"
Const PATH_TO_OUTPUT = "out.txt"
Dim fso
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
Dim shl
Set shl = WScript.CreateObject("WScript.Shell")
Dim input
Set input = fso.OpenTextFile(PATH_TO_INPUT)
Dim output
Set output = fso.CreateTextFile(PATH_TO_OUTPUT, True)
Dim wmiService
Dim wmiResults
Dim objwMIService
Dim colFiles
Dim objFile
Dim hostname
Dim line
Dim exec
Dim pingResults
While Not input.AtEndOfStream
line = input.ReadLine
hostname = ""
Set exec = shl.Exec("ping -n 2 -w 500 " & line)
pingResults = LCase(exec.StdOut.ReadAll)
If InStr(pingResults, "reply from") Then
WScript.Echo "Reply From: " & line
hostname = line
Set objWMIService = GetObject("winmgmts:\\" & hostname & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_Datafile Where Extension = 'pst' OR Extension = 'pdf' OR Extension = 'doc' OR Extension = 'xls'")
For Each objFile in colFiles
output.WriteLine hostname & "," & objFile.Name & "," & objFile.FileSize
Next
Else
WScript.Echo line & " no response"
End If
Wend
output.Close
input.Close
Set wmiService = Nothing
Set wmiresults = Nothing
No comments:
Post a Comment