$dir = "C:\temp"
$latest = Get-ChildItem -Recurse -Filter filename*.txt -Path $dir | Sort-Object
LastAccessTime -Descending | Select-Object -First 1
$SEL = get-content $latest
if( $SEL -imatch "error" )
{
Write-Host 'Errors found in the log file'
#send email code to be added
}
else
{
Write-Host 'No Errors'
}
我已经尝试过这段代码,目前它运行良好。但是想要确保代码在同一给定时间有两个最新的文本文件时也能正常工作。