function Get-LatestFile([string]$FilePath, [int]$NumDaysAgo){ $DateToCompare = (Get-date).AddDays(-$NumDaysAgo) return get-childitem $FilePath | where-object {$_.lastwritetime –gt $DateToCompare}
}
$LatestFile = Get-LatestFile "\\server\share\" 7
So basically you supply the folder location and the time frame. The above command will look for the latest file in the past seven (7) days in the location specified.

0 comments:
Post a Comment