Example of folder structure:
Projects 1-1000
***Project 1
******Project 1.1
******Project 1.2
There are thousands of projects which is why they are grouped 1-1000, 1001-2000, etc.
Ideally, the final list would look like this:
Folder Path\Project 1.1 July 21, 2000
Folder Path\Project 1.2 May 22, 2017
etc.
The date being the latest modified date of anything in the folder (Project 1.1) or any of the many sub-folders within Project 1.1 and so on for Project 1.2.
Our attorney will then choose how many years back we need to keep the data, so she may say Project 1.1 can be deleted because of how old it is.
This code works great, but I need to somehow add the -depth parameter to start at the Project 1.1 level.
How do I modify this to start at the Project 1.1 level?
- $Result = Get-ChildItem -Path '.\Program 1\Projects 1-1000\*' -Directory |
- ForEach-Object {
- $NewestItem = Get-ChildItem -Path $_.FullName -File -Recurse | Sort-Object -Property LastWriteTime | Select-Object -Last 1
- [PSCustomObject]@{
- Folder = $_.FullName
- NewestItem = $NewestItem.FullName
- NewestItemDate = $NewestItem.LastWriteTime
- }
- }
- $Result | Export-Csv -Path .\output.csv -NoTypeInformation