使用此脚本可以收集文件夹中所有文件的生成数量并导出到一个日志文件或Excel中。
'=======================================
' COllectLogs.vbs
'
' Copyright (c) 2005, Microsoft Corporation. All Rights Reserved.
'
' THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
' KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
' IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
' PARTICULAR PURPOSE.
'
' Description: This script will collect transaction log data
' as they are generated.
'
' Written by: Ross Smith IV (Microsoft)
'
' Version: 1.0
' Last Updated: 7/3/07
'=======================================
'=====================================================
'Define Variables & Constants
'=====================================================
Const ForAppending = 8
strComputer = "."
'=====================================================
'Determine if CSCRIPT must be used
'=====================================================
if InStr(1,wscript.fullname,"cscript.exe",1) = 0 then
wscript.echo "This script should be run using 'cscript.exe <scriptfile>'. Terminating script."
wscript.quit
end if
'=====================================================
' Parse command-line arguments
'=====================================================
Set oArg = wscript.arguments
if oArg.Count = 0 then ' we need the arguments
DisplayHelpMessage
wscript.quit
End If
For i = 0 to oArg.Count - 1
'Get Log Folder Value
If LCase(Left(oArg.Item(i),3)) = "-l:" then
strLogFolder = Mid(oArg.Item(i),4)
'wscript.echo strLogFolder
end if
'Get Output file name
If LCase(Left(oArg.Item(i),3)) = "-o:" then
strOutputFile = Mid(oArg.Item(i),4)
'wscript.echo strOutputFile
end if
Next
'=====================================================
' Main Function
'=====================================================
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile (strOutputFile, ForAppending, True)
Set colFileList = objWMIService.ExecQuery ("ASSOCIATORS OF {Win32_Directory.Name='" & strLogFolder & "'} Where " & "ResultClass = CIM_DataFile")
For Each objFile In colFileList
objTextFile.WriteLine(objFile.FileName & "." & objFile.Extension & vbTab & WMIDateStringToDate(objFile.LastModified))
'Wscript.Echo objFile.Name & " " & WMIDateStringToDate(objFile.LastModified)
Next
Function WMIDateStringToDate(dtmDate)
WScript.Echo dtm:
WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) & " " & Mid (dtmDate, 9, 2) & ":" & Mid(dtmDate, 11, 2) & ":" & Mid(dtmDate,13, 2))
End Function
'=====================================================
' Help Listing
'=====================================================
Sub DisplayHelpMessage()
wscript.echo "Description: This script will collect the number of transaction logs generated"
wscript.echo " for a given storage group and record them in a text file."
wscript.echo ""
wscript.echo "Usage: CollectLogs.vbs -l:<Log Folder> -o:<Output File Name>"
wscript.echo ""
wscript.echo "Required Arguments:"
wscript.echo ""
wscript.echo "-l:<Log Folder>"
wscript.echo "Specify the Transaction Log Folder"
wscript.echo "Ex: d:\sg1logs"
wscript.echo ""
wscript.echo "-o:<Output File Name>"
wscript.echo "Specify the Output file"
wscript.echo "Ex: c:\output\sg1output.log"
wscript.echo ""
wscript.echo "Example: CollectLogs.vbs -l:d:\sg1logs -o:c:\output\sg1output.log"
End Sub