我的任务是对所有服务器上的所有事件日志进行备份并保留30天。 我写了一个简单的PowerShell来做到这一点。
Get-winevent -Listlog * | select Logname, Logfilepath | ForEach-Object -Process { $name = $_.Logname $path = $_.logfilepath wevtutil.exe EPL $name C:\Users\Owner\Desktop\eventlogs\$name.evtx` }
这只导出NTclassic事件日志的日志文件,对于其他日志我得到一个系统找不到path指定的错误。 我改变了wevtutil并且包含了/ lf参数并且传递了$ pathvariables,它仍然是一样的。 除了传统的日志以外,其他的东西都是我得到的错误。
wevtutil.exe : Failed to export log Microsoft-Windows-WPD-MTPClassDriver/Operational. The system cannot find the path specified. At line:19 char:1 + wevtutil.exe EPL $name C:\Users\Owner\Desktop\eventlogs\$name.evtx + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (Failed to expor...path specified.:String) [], RemoteException + FullyQualifiedErrorId : NativeCommandErrorBlockquote
有没有其他更好的方法来完成我想要做什么?
问题是$namevariables。 如果你检查哪个导出文件被创build,你会注意到所有包含正斜杠的日志名字都会产生错误信息。 这是因为/是文件名中的无效字符(在Windows下)。
您可以通过将/replace为有效的字符来运行导出:
Get-winevent -Listlog * | select Logname, Logfilepath | ForEach-Object -Process { $name = $_.Logname $safename = $name.Replace("/","-") wevtutil.exe EPL $name C:\Users\Owner\Desktop\eventlogs\$safename.evtx }
你可以安装一个集中的系统日志服务器(即Graylog ),并将所有的事件从NXLog转发 。 通过这种方式,您将获得卓越的可pipe理性和日志安全性。