Hi everyone,
I created the following vbscript code to search remote pc's/servers on our network for media files by looking for file extentions. The script works fine on all PCs and some servers, yet if I scan a server with over 1Tb of disk space the script runs but doesn't seem to produce an output file. Is there any limitations on the amount of data these script can process? or does anyone have any better suggestions on how to search for these files?
Thanks in advance, Lee.
Here is the code,
Option Explicit
'this subroutine creates and arranges the text file
Sub writeToLogFile(strLogFile, strLogMessage)
Dim objFso, objLogFile
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objLogFile = objFspenTextFile(strLogFile, 8, True)
objLogFile.WriteLine(strLogMessage)
objLogFile.Close
Set objLogFile = Nothing
Set objFso = Nothing
End Sub
Dim strServerName
'this prompts the user for an input
strServername=InputBox("Which server do you want to search for media files? ","newmediafilecheck.vbs","Servername")
'specify the output location for the results
Dim strMediaFilesFound, arrDates, strDebugLog
arrDates = split(Date, "/")
strMediaFilesFound = "C:\" & ucase(strServername) & "_" & "MediaFilesReport" & arrDates(2) & arrDates(1) & arrDates(0) & Replace(Time, ":", "") & ".txt"
strDebugLog = "C:\" & ucase(strServername) & "_" & "DebugLogReport" & arrDates(2) & arrDates(1) & arrDates(0) & Replace(Time, ":", "") & ".txt"
'if nothing is entered the script ends
If strServername="Servername" Then
wscript.echo "Nothing entered or you cancelled"
wscript.quit
End If
'if cancelled then script aborts
If strServername = "" Then
'~ "" = no, so abort with a message:
MsgBox "OK, Aborting.", 64, "MediaFileCheck.vbs"
WScript.Quit
End If
' Dim objItem, colItems, strComputer, SumFiles
' object to represetn WMI interface on server:
Dim objWMIService
' Instantiate WMI object on target server, handle and report any errors:
On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strServername & "\root\cimv2")
If Err.Number <> 0 Then
writeToLogFile strDebugLog, "Can't connect to WMI interface on " & strServername
wscript.echo "Can't connect to WMI interface on " & strServername
wscript.quit
End If
On Error Goto 0
' Collection to hold list of local disks on server:
Dim colDisks
' Get a list of physical volumes on the server:
'Set colDisks = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk WHERE DriveType=3")
'this is the file extensions the script will search for:
Dim arrExtensions
arrExtensions = Array("mp3","vob","mp4","wma","mov","aac","wav","mpeg","3gp","midi","avi","mpg","wmv")
' Variable to use to go through arrExtensions
Dim strExtension
For Each strExtension In arrExtensions
' Collection to hold list of qualifying files:
Dim colFileList
Set colFileList = objWMIService.ExecQuery("SELECT Name,FileSize FROM CIM_Datafile WHERE Extension = '" & strExtension & "'")
' Variable to go through colFileList:
Dim objFile
For Each objFile In colFileList
writeToLogFile strMediaFilesFound, "\\" & strServername & "\" & Replace(objFile.name, ":", "$") & vbTab & Round(objFile.FileSize / 1024 / 1024, 2) & "Mb"
Next
Set colFileList = Nothing
Next
' clean up
'Next
Set objWMIService = Nothing
MsgBox "Script complete.", 64, "MediaFilesSearch.vbs"
I created the following vbscript code to search remote pc's/servers on our network for media files by looking for file extentions. The script works fine on all PCs and some servers, yet if I scan a server with over 1Tb of disk space the script runs but doesn't seem to produce an output file. Is there any limitations on the amount of data these script can process? or does anyone have any better suggestions on how to search for these files?
Thanks in advance, Lee.
Here is the code,
Option Explicit
'this subroutine creates and arranges the text file
Sub writeToLogFile(strLogFile, strLogMessage)
Dim objFso, objLogFile
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objLogFile = objFspenTextFile(strLogFile, 8, True)
objLogFile.WriteLine(strLogMessage)
objLogFile.Close
Set objLogFile = Nothing
Set objFso = Nothing
End Sub
Dim strServerName
'this prompts the user for an input
strServername=InputBox("Which server do you want to search for media files? ","newmediafilecheck.vbs","Servername")
'specify the output location for the results
Dim strMediaFilesFound, arrDates, strDebugLog
arrDates = split(Date, "/")
strMediaFilesFound = "C:\" & ucase(strServername) & "_" & "MediaFilesReport" & arrDates(2) & arrDates(1) & arrDates(0) & Replace(Time, ":", "") & ".txt"
strDebugLog = "C:\" & ucase(strServername) & "_" & "DebugLogReport" & arrDates(2) & arrDates(1) & arrDates(0) & Replace(Time, ":", "") & ".txt"
'if nothing is entered the script ends
If strServername="Servername" Then
wscript.echo "Nothing entered or you cancelled"
wscript.quit
End If
'if cancelled then script aborts
If strServername = "" Then
'~ "" = no, so abort with a message:
MsgBox "OK, Aborting.", 64, "MediaFileCheck.vbs"
WScript.Quit
End If
' Dim objItem, colItems, strComputer, SumFiles
' object to represetn WMI interface on server:
Dim objWMIService
' Instantiate WMI object on target server, handle and report any errors:
On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strServername & "\root\cimv2")
If Err.Number <> 0 Then
writeToLogFile strDebugLog, "Can't connect to WMI interface on " & strServername
wscript.echo "Can't connect to WMI interface on " & strServername
wscript.quit
End If
On Error Goto 0
' Collection to hold list of local disks on server:
Dim colDisks
' Get a list of physical volumes on the server:
'Set colDisks = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk WHERE DriveType=3")
'this is the file extensions the script will search for:
Dim arrExtensions
arrExtensions = Array("mp3","vob","mp4","wma","mov","aac","wav","mpeg","3gp","midi","avi","mpg","wmv")
' Variable to use to go through arrExtensions
Dim strExtension
For Each strExtension In arrExtensions
' Collection to hold list of qualifying files:
Dim colFileList
Set colFileList = objWMIService.ExecQuery("SELECT Name,FileSize FROM CIM_Datafile WHERE Extension = '" & strExtension & "'")
' Variable to go through colFileList:
Dim objFile
For Each objFile In colFileList
writeToLogFile strMediaFilesFound, "\\" & strServername & "\" & Replace(objFile.name, ":", "$") & vbTab & Round(objFile.FileSize / 1024 / 1024, 2) & "Mb"
Next
Set colFileList = Nothing
Next
' clean up
'Next
Set objWMIService = Nothing
MsgBox "Script complete.", 64, "MediaFilesSearch.vbs"