You'll need PowerShell 5.x otherwise, the -Directory
switch of Get-ChildItem
will not be available:
Get-ChildItem -Path . -Directory -Recurse | Where-Object { $_.LastWriteTime -lt (Get-Date "2018-10-04") } | Export-Csv "test.csv" -NoTypeInformation -Delimiter ";"
Get-ChildItem -Path . -Directory -Recurse
- Get all directories
Where-Object { $_.LastWriteTime -lt (Get-Date "2018-10-04") }
- check if the last write time is older than 2018-10-04 (you may also use LastAccessTime
)
Export-Csv "test.csv" -NoTypeInformation -Delimiter ";"
- exports the filtered objects to CSV file.
If you want less information in the CSV file you can use Select-Object
:
Get-ChildItem -Path . -Directory -Recurse | Where-Object { $_.LastWriteTime -lt (Get-Date "2018-10-04") } |Select-Object Name, PSPath, Parent | Export-Csv "test.csv" -NoTypeInformation -Delimiter ";"
To get available properties use Get-Member
:
Get-ChildItem -Path . -Directory -Recurse | Where-Object { $_.LastWriteTime -lt (Get-Date "2018-10-04") } | Get-Member
Output:
TypeName: System.IO.DirectoryInfo
Name MemberType Definition
---- ---------- ----------
LinkType CodeProperty System.String LinkType{get=GetLinkType;}
Mode CodeProperty System.String Mode{get=Mode;}
...
FullName Property string FullName {get;}
LastAccessTime Property datetime LastAccessTime {get;set;}
LastAccessTimeUtc Property datetime LastAccessTimeUtc {get;set;}
LastWriteTime Property datetime LastWriteTime {get;set;}
LastWriteTimeUtc Property datetime LastWriteTimeUtc {get;set;}
Name Property string Name {get;}
...
Attributes Property System.IO.FileAttributes Attributes {get;set;}
CreationTime Property datetime CreationTime {get;set;}
CreationTimeUtc Property datetime CreationTimeUtc {get;set;}
...
From here you can use the *Property
member types in Select-Object
and Where-Object
.
If you are on PowerShell less than 5, you've to check the PSIsContainer
property, as explained in this stackoverflow answer.
Hope that's the information you're looking for.