Window PowerShell
2 TopicsRestricting PowerShell folder search to a specific date range
The help I've received here has been invaluable, and as expected, once something good has been accomplished, there are always new requirements. So... Thanks in advance for continuing to assist this PowerShell novice. How can I modify this code to restrict the results to only include LastWriteTimes in CY23? $dirs = Get-ChildItem "\\Myorg\firstlevel\secondlevel\thirdlevel\Ion" -Directory $csvLog = "\\Myorg\output\fileshare\mystuff\Documents\PowerShellOutput\Latest Ion Trend Files Size Counts.csv" foreach ($dir in $dirs) { $recentFile = $null $folder = $dir.Name $directory = $dir.FullName $filesCount = (Get-ChildItem $directory -Filter "trend*.pqd" -Recurse).Count $recentFile = Get-ChildItem $directory -Filter "trend*.pqd" -Recurse | Sort-Object LastWriteTime -Descending| Select-Object -First 1 $recentFileName = $recentFile.Name $recentFileLength = $recentFile.Length $recentFileWriteTime = $recentFile.LastWriteTime if ($recentFile) { $object = New-Object -TypeName psobject $object | Add-Member -MemberType NoteProperty -Name "Site" -Value $folder $object | Add-Member -MemberType NoteProperty -Name "File Name" -Value $recentFileName $object | Add-Member -MemberType NoteProperty -Name "File Size" -Value $recentFileLength $object | Add-Member -MemberType NoteProperty -Name "Date Time" -Value $recentFileWriteTime $object | Add-Member -MemberType NoteProperty -Name "File Count" -Value $filesCount $object | Export-Csv $csvLog -Encoding ASCII -Append -NoTypeInformation } }Solved8.9KViews0likes4Comments