切换到宽版
  • 7712阅读
  • 0回复

[求助]使用脚本收集日志生成率 [复制链接]

上一主题 下一主题
 
只看楼主 倒序阅读 0楼  发表于: 2011-03-19
— 本帖被 YOYO 从 Exchange 脚本中心 移动到本区(2015-06-25) —
  • 脚本环境:Visual Basic
  • 适合版本:Exchange 2007
  • 适用平台:
  • 脚本作用:收集Exchange相关文件的生成数量
使用此脚本可以收集文件夹中所有文件的生成数量并导出到一个日志文件或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



分享到
快速回复
限60 字节
 
上一个 下一个