Quantcast
Channel: VBForums - ASP, VB Script
Viewing all articles
Browse latest Browse all 686

Find Top big files on E drive

$
0
0
Hi,

A small help need.

I want to find all files more then 500mb+ from my E drive where file archive attribute is ON. [Means they are ready for backup], and result will be saved in txt file in c: drive.

In powershell it's a just one liner, but I am new VBS and I want to run against Win2003 servers and no powershell on them for some reason.

Can any one help me.

Attaching sample script I found on Internet.


Code:

Option Explicit

Call EnumFileInfo
 
Private Sub EnumFileInfo()
 ' Written by: Eli Sabo
 ' Dated: 6-23-2011
 
' Script that  runs on the computer
' it  is invoked  on and  finds all
' OST files. Then writes them to an
' output file along with file size and date modified

'7/6/2012
'Modified by Zippo to only select the largest "PST" file opened within the last 7 days
 
        On Error Resume Next
       
' Declare the local variables
 
        Dim fso, WshShell, objWMIService, objFile, oFile
        Dim strComputer, strHeader, strOutput
        Dim colFiles, fileModifiedDate, strOutputString
        Dim i, myDate
        Dim adoRS
 
        Const ForWriting = 2
        Const adVarChar = 200
        Const MaxCharacters = 1500
       
' Create Objects
 
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set WshShell = CreateObject("Wscript.Shell")
        Set adoRS = CreateObject("ADODB.Recordset")

        adoRS.Fields.Append "Name", adVarChar, MaxCharacters
        adoRS.Fields.Append "FileSize", adVarChar, MaxCharacters
        adoRS.Fields.Append "LastModifiedDate", adVarChar, MaxCharacters
       
 
' Start Script
        strComputer = "."
        strHeader = "File Path , File Size , Date Last Modified"
       
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")

Set colFiles = objWMIService.ExecQuery("Select Name, FileSize, LastModified from CIM_DataFile where Drive = 'C:' AND Extension LIKE 'pst'")


i = 0
wscript.echo "Beginning search. Be patient as this will take a while...Will notify when completed."
adoRS.Open
        For Each objFile in colFiles
                If INSTR(UCASE(objFile.Name), "PST") Then
                        adoRS.AddNew
                        adoRS.Fields("Name").Value = objFile.Name
                        adoRS.Fields("FileSize").Value = objFile.FileSize
                        adoRS.Fields("LastModifiedDate").Value = objFile.LastModified
                        adoRS.Update
                End If
        i=i+1
        Next
 
        adoRS.Sort = "FileSize DESC, LastModifiedDate DESC"

        adoRS.MoveFirst

 ' WRITE RESULTS - Open the file. ALWAYS OVERWRITES OLD FILE

        Set oFile = fso.CreateTextFile("C:\TabushSMA\PSTOST_Files.txt", True, False)
 
                If Err.Number <> 0 Then
                        WScript.Echo "Error opening file: " & strOutputFile & " - Error Number - " & Err.Number
                        Exit Sub
                End If
 

If Not (adoRS.BOF AND adoRS.EOF) Then
        oFile.WriteLine(strHeader)
        myDate = (Date() - 7)
        'Do While Not adoRS.EOF
                fileModifiedDate = WMIDateStringToDate(adoRS.Fields("LastModifiedDate").Value)

                If (cDate(fileModifiedDate) >= cDate(myDate)) Then
                        'strOutputString = adoRS.Fields("Name").Value & ", "
                        'strOutputString = strOutputString & fsize(adoRS.Fields("FileSize").Value) & ", "
                        strOutputString = strOutputString & fsize(adoRS.Fields("FileSize").Value)
                        'strOutputString = strOutputString & fileModifiedDate
                        oFile.WriteLine(strOutputString)
                End If
        'adoRS.MoveNext
        'Loop
Else

oFile.WriteLine("No PST Files Found...")

End If

oFile.Close
 
' Release the object from memory
        Set oFile = Nothing
        Set adoRS = Nothing
        Err.Clear
 
WScript.Echo "Done!"

End Sub

Function fsize(Bytes)

    If Bytes > 0 And Bytes < 1024 Then

            fsize = Bytes & " Bytes"

        ElseIf Bytes >= 1024 And Bytes < 1048576 Then

            fsize = Round((Bytes/1024),2) & " KB"

        ElseIf Bytes >= 1048576 And Bytes < 1073741824 Then

            fsize = Round((Bytes/1048576),2) & " MB"

        ElseIf Bytes >= 1073741824 Then

            fsize = Round((Bytes/1073741824),2) & " GB"

    End IF

End Function

Function WMIDateStringToDate(dtmStart)
    WMIDateStringToDate = CDate(Mid(dtmStart, 5, 2) & "/" & _
        Mid(dtmStart, 7, 2) & "/" & Left(dtmStart, 4) _
            & " " & Mid (dtmStart, 9, 2) & ":" & _
                Mid(dtmStart, 11, 2) & ":" & Mid(dtmStart, _
                    13, 2))
End Function


Viewing all articles
Browse latest Browse all 686

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>