我知道这个问题已被问过几次,但我的要求与我在这里和谷歌上看到的略有不同 .
我有以下文件夹结构 .
c:\weblogs\Servers\Server1
c:\weblogs\Servers\Server2
Server 1文件夹可能包含以下文件夹:
W3SVC1
W3SVC2
W3SVC3
服务器2将具有类似的文件夹结构 .
我正在尝试创建一个脚本,该脚本将查看每个 W3SVC* 文件夹,查找超过30天的 .log 文件 .
然后它会在每个这样的 W3SVC* 子文件夹中创建一个名为 Oldlogs-Server*-W3SVC*.zip 的zip文件,并将旧日志移动到该文件 . 在第二次运行时,它只会将超过30天的任何新文件移动到相应的zip文件 .
我不是开发人员,但如果没有可用的现有脚本,任何示例或建议都会有所帮助 .
这是我认为最接近我想要实现的脚本:
它目前抛出一个错误:
“\ WebApps \ LogHarvest \ pkzipc.exe需要”
# Alias for pkzip
if (-not (test-path "$env:F:\WebApps\LogHarvest\pkzipc.exe")) {
throw "$env:F:\WebApps\LogHarvest\pkzipc.exe needed"
}
set-alias sz "$env:WebApps\LogHarvest\pkzipc.exe"
############################################
#### Variables
$filePath = "F:\Weblogs\Test"
$log = Get-ChildItem -Recurse -Path $filePath | Where-Object { $_.Extension -eq ".log" }
########### END of VARABLES ##################
foreach ($file in $log) {
$name = $file.name
$directory = $file.DirectoryName
$zipfile = $name.Replace(".log",".7z")
sz a -t7z "$directory\$zipfile" "$directory\$name"
}
########### END OF SCRIPT ##########