Code as it is at the moment
get-childitem c:\pstbak\*.* -include *.pst | Where-Object { $_.LastWriteTime -lt (get-date).AddDays(-3)} |
Essentially what I am trying to do is get a list of all PST files in the folder above based on them being newer than 3 days old. I'd then like to count the results. The above code doesn't error but brings back zero results (there are definitely PST files in the folder that are newer than three days. Anyone have any idea?
Description. The Get-ChildItem cmdlet gets the items in one or more specified locations. If the item is a container, it gets the items inside the container, known as child items. You can use the Recurse parameter to get items in all child containers and use the Depth parameter to limit the number of levels to recurse.
Use the Get-ChildItem LastWriteTime attribute to find the list of files with lastwritetime. Get-ChildItem in the PowerShell gets one or more child items from the directory and subdirectories.
PowerShell utilizes the “Get-ChildItem” command for listing files of a directory. The “dir” in the Windows command prompt and “Get-ChildItem” in PowerShell perform the same function.
Try this:
(Get-ChildItem -Path c:\pstbak\*.* -Filter *.pst | ? {
$_.LastWriteTime -gt (Get-Date).AddDays(-3)
}).Count
Very similar to previous responses, but the is from the current directory, looks at any file and only for ones that are 4 days old. This is what I needed for my research and the above answers were all very helpful. Thanks.
Get-ChildItem -Path . -Recurse| ? {$_.LastWriteTime -gt (Get-Date).AddDays(-4)}
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