简体   繁体   中英

How to add information to (gci -filter *.* -recurse).FullName (ie:LastWrite, Modified By, Etc)

I am an absolute noob when it comes to Powershell..

Currently I run a simple script to get a file listing across our server.

(gci -filter *.xl* -recurse).FullName > AllExcel.txt

It gives me exactly what I'm looking for, a directory path and the file name all on one line across all subdirectories.

X:\00\This file 1.xls
X:\00\This file 2.xls
X:\aaa\This file Too 1.xls
X:\aaa\This file Too 2.xls

Can I add The date/time the file was last modified for each item? {$_.LastWriteTime}?

If so, can the output be sorted by this date/time? Would prefer newest at the top if possible.

are there also options to get who last modified a file?

Instead of a simple text file, I would store the results in a structured CSV file.

Get-ChildItem -Path 'X:\' -Filter '*.xls*' -File -Recurse | 
Select-Object FullName, LastWriteTime |
Sort-Object LastWriteTime -Descending |
Export-Csv -Path 'X:\Somewhere\AllExcel.csv' -NoTypeInformation -UseCulture

This will result in a structured CSV file you can open on a machine with the same regional settings as yours to open in Excel

As for who last modified the files:
You could use Get-Acl on each file and with that get the Owner, but whoever owns the file is not necessarily the one who created/modified it. You cannot identify creator or user who made the last change in Windows unless have file and folder auditing enabled beforehand, so you can extract the information from the audit logs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM