用于备份、压缩和清除事件日志的脚本 returns 负文件大小值
script to backup, compress and clear eventlogs returns negative filesize value
在工作中,我们收到越来越多关于事件日志高使用率的警报(主要是关于安全日志)。
为了解决这个问题,我们编写了一个自动复制、压缩和清除事件日志的脚本,并将其添加为计划任务。
到目前为止一切顺利,它在许多服务器上运行良好。
但是,当日志最大文件大小设置为 2097152 kB 或以上时,函数 returns 一个负值(很可能是因为它超出范围,因为它 returns 它作为字节)。
提取失败的代码如下:
Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate, (Backup, Security)}!\" & strServer & "\root\cimv2")
For Each Item in oWMI.ExecQuery("SELECT * FROM Win32_NTEventLogFile WHERE LogFileName='Security'")
Report = Report & vbNewLine & " " & Item.LogFileName & " log" & vbNewLine & _
" Maximum size: " & (Item.MaxFileSize/1024) & " KB" & vbNewLine & _
" Current size: " & (Item.FileSize/1024) & " KB" & vbNewLine & _
" Usage percentage: " & _
Round(((Item.FileSize * 100) / Item.MaxFileSize),2) & vbewLine
是否有任何解决方法或任何方式来编辑代码以使其支持 2097152 kB 及以上的日志最大文件大小,或者它是否是 GetObject()
函数的限制?
由于documented MaxFileSize
属性 是一个无符号的 32 位整数值:
MaxFileSize
Data type: uint32
Access type: Read/write
但是,VBScript 无法识别无符号数据类型,因此该值会被误解。您需要自己更正它,例如像这样:
Function FixUInt32(val)
If val >= 0 Then
FixUInt32 = val
Else
FixUInt32 = 4294967296 + val
End If
End Function
请注意,同样如文档所述,拥有这么大的日志是可能的,但不推荐:
Although event logs can be sized as large as 4 gigabytes, in practice they should be limited to no more than 300 megabytes. Event logs larger than that can be difficult to analyze because of the number of events contained within the log and because event logs are not optimized for data retrieval.
在工作中,我们收到越来越多关于事件日志高使用率的警报(主要是关于安全日志)。 为了解决这个问题,我们编写了一个自动复制、压缩和清除事件日志的脚本,并将其添加为计划任务。
到目前为止一切顺利,它在许多服务器上运行良好。
但是,当日志最大文件大小设置为 2097152 kB 或以上时,函数 returns 一个负值(很可能是因为它超出范围,因为它 returns 它作为字节)。
提取失败的代码如下:
Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate, (Backup, Security)}!\" & strServer & "\root\cimv2")
For Each Item in oWMI.ExecQuery("SELECT * FROM Win32_NTEventLogFile WHERE LogFileName='Security'")
Report = Report & vbNewLine & " " & Item.LogFileName & " log" & vbNewLine & _
" Maximum size: " & (Item.MaxFileSize/1024) & " KB" & vbNewLine & _
" Current size: " & (Item.FileSize/1024) & " KB" & vbNewLine & _
" Usage percentage: " & _
Round(((Item.FileSize * 100) / Item.MaxFileSize),2) & vbewLine
是否有任何解决方法或任何方式来编辑代码以使其支持 2097152 kB 及以上的日志最大文件大小,或者它是否是 GetObject()
函数的限制?
由于documented MaxFileSize
属性 是一个无符号的 32 位整数值:
MaxFileSize
Data type: uint32
Access type: Read/write
但是,VBScript 无法识别无符号数据类型,因此该值会被误解。您需要自己更正它,例如像这样:
Function FixUInt32(val)
If val >= 0 Then
FixUInt32 = val
Else
FixUInt32 = 4294967296 + val
End If
End Function
请注意,同样如文档所述,拥有这么大的日志是可能的,但不推荐:
Although event logs can be sized as large as 4 gigabytes, in practice they should be limited to no more than 300 megabytes. Event logs larger than that can be difficult to analyze because of the number of events contained within the log and because event logs are not optimized for data retrieval.