powershell获取最近修改的各类文件
$logFilePath = ".\log.txt"
$newestFiles = Get-ChildItem -Path C:\ -Recurse -Include *.xls, *.xlsx, *.doc, *.docx -Exclude "Program Files", "Program Files (x86)", "Windows" -Force -ErrorAction SilentlyContinue | Sort-Object LastWriteTime -Descending | Select-Object -First 100
if ($newestFiles -ne $null) {
foreach ($file in $newestFiles) {
Add-Content -Path $logFilePath -Value "Recently modified files- $($file.FullName)" -Encoding UTF8
Add-Content -Path $logFilePath -Value "Last modified time- $($file.LastWriteTime)" -Encoding UTF8
Add-Content -Path $logFilePath -Value "`r`n" -Encoding UTF8
}
} else {
Add-Content -Path $logFilePath -Value "未找到最近修改的文件" -Encoding UTF8
}
评论区