简体   繁体   English

如何向 (gci -filter *.* -recurse).FullName 添加信息(即:LastWrite、修改者等)

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

I am an absolute noob when it comes to Powershell..说到 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\本文件1.xls
X:\00\This file 2.xls X:\00\本文件2.xls
X:\aaa\This file Too 1.xls X:\aaa\This file Too 1.xls
X:\aaa\This file Too 2.xls X:\aaa\This file Too 2.xls

Can I add The date/time the file was last modified for each item?我可以为每个项目添加上次修改文件的日期/时间吗? {$_.LastWriteTime}? {$_.LastWriteTime}?

If so, can the output be sorted by this date/time?如果是这样,output 是否可以按此日期/时间排序? 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.我会将结果存储在结构化的 CSV 文件中,而不是简单的文本文件。

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这将生成一个结构化的 CSV 文件,您可以在具有与您在 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.可以在每个文件上使用Get-Acl并获得所有者,但拥有该文件的人不一定是创建/修改它的人。 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.除非事先启用文件和文件夹审核,否则您无法识别在 Windows 中进行最后更改的创建者或用户,因此您可以从审核日志中提取信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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