I'm trying to find all files that include some string and are not older than "x" days. Those files have to be sorted and then sent in .txt format.
The code seemed fine to me, but it doesn´t filter files by date. All other cmdlets work as intended, but the part Where-Object {$_.LastWriteTime -ge (Get-Date).AddDays(-$days)}
doesn´t seem to be working at all.
Do you have any recommendations how to fix it?
Get-ChildItem -Path $path -Recurse |
Where-Object {$_.LastWriteTime -ge (Get-Date).AddDays(-$days)} |
Select-String -Pattern $searched |
Group-Object -Property Path, Filename |
select Name |
Out-File -Filepath C:\tmp\output.txt
| Sort-Object -Property propertyName -Descending
cmdlet to sort by property value reference link - https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/sort-object?view=powershell-6
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With