使用powershell的zip事件日志

时间:2019-05-21 15:59:32

标签: powershell

我是Powershell的新手,在为我的工作编写此脚本时需要一些帮助。

我有几个月的事件日志存储在驱动器中,我想使用powershell压缩所有这些事件日志,但是由于文件名带有时间戳,我绝对不知道如何启动。

首先,我想有1个脚本根据导出的月份压缩所有日志。然后再压缩一个月前的用于将来日志的脚本。我计划让第二个脚本按月运行。

衷心感谢您的事先帮助!

我考虑了脚本的运行流程。

清理事件日志脚本

Define Drive = F drive

function findeventlog
Get current month = eg. May
Find all files earlier than [get current month] 
Get current year
define exclusion list of zip files = "*.zip"
filter "[get current year]-[get current month]-*"

define event log folder = Drive\eventlogbackup\eventlogs 
define zip destination folder = F:\eventlogbackup\eventlog -filter -recurse

define zips to create = find items in event log folder and exclude (list)
define zips to create.count
zip (define zips to create)

压缩事件日志脚本的处理流程

Define Drive = F drive

function findeventlog
Get current month = eg. May
Find all files 1 month earlier than [get current month] 
Get current year
define exclusion list of zip files = "*.zip"

define event log folder = Drive\eventlogbackup\eventlogs -filter -recurse
define zip destination folder = F:\eventlogbackup\eventlog

define zips to create = find items in event log folder and exclude (list)
define zips to create.count
zip (define zips to create)

2 个答案:

答案 0 :(得分:0)

伪代码方法的荣誉。由于脚本将需要比平时更多的工作,因此让我尝试CW答案。尝试从脚本中继续前进,并随时向具体问题寻求帮助。

</p> <script> console.log("I'm working!") </script>
= <p></p>

<script> console.log("I'm working!") </script>
= <p></p>

hello
= <p>hello</p>

hello <p>
= <p>hello</p><p></p>

<p>
= <p></p><p></p>

<script>
= <p></p>

<asdasd></asdasd>
=<p><asdasd></asdasd></p>

function(){console.log("hey")}
=<p></p>

( () => { console.log("hey") } )
=<p></p>

答案 1 :(得分:0)

谢谢。这确实有帮助。我提出了一些建议,但是绝对需要进一步的微调。这就是我所拥有的。我使用的是答案,因为评论太长了。

$drive = "F:"
$exclude = @("whatever.evtx")
$eventlogfolder = "$drive\destinationpath"
$filesApr = Get-ChildItem -path $eventlogfolder -exclude $exclude | where-object {$_.lastwritetime -le (Get-date).AddMonths(-1)}

compress-archive $filesApr -Destinationpath $eventlogfolder\ArchiveApr2019.zip -force -confirm:false

我的问题: 1.如果我的事件日志的日期是从一月到四月,那么如何使我的脚本成为函数,这样我就不需要指定月份了? 2.当我不指定月份时,是否可以将其过滤到月份中进行压缩?例如05-04-2019.evtx应该压缩到ArchiveApr2019.zip

欢迎任何其他建议来微调我的脚本!我会不断学习和改进。

相关问题