I have to create a list of all latest or accessed files in a directory in .csv format. However my current script doesn't output a useful file. (always 0KB)
Get-ChildItem -Path X:\ -Directory -Recurse -ErrorAction SilentlyContinue |
ForEach-Object { Get-ChildItem $_.Name -Recurse |
select Name, *time |
Sort-Object -Property LastAccessTime -Descending |
Select-Object -First 1 } |
Export-Csv -Path C:\...\testfile.csv
Does anyone have a better idea?
EDIT: The errors look like this:
+ CategoryInfo : ReadError: (X:\xxx:String) [Get-ChildItem], DirectoryNotFoundException
+ FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand