![如何使用命令提示符查找文件的以下元数据:作者、上次保存者、所有者、创建者?](https://linux22.com/image/1631320/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%E5%91%BD%E4%BB%A4%E6%8F%90%E7%A4%BA%E7%AC%A6%E6%9F%A5%E6%89%BE%E6%96%87%E4%BB%B6%E7%9A%84%E4%BB%A5%E4%B8%8B%E5%85%83%E6%95%B0%E6%8D%AE%EF%BC%9A%E4%BD%9C%E8%80%85%E3%80%81%E4%B8%8A%E6%AC%A1%E4%BF%9D%E5%AD%98%E8%80%85%E3%80%81%E6%89%80%E6%9C%89%E8%80%85%E3%80%81%E5%88%9B%E5%BB%BA%E8%80%85%EF%BC%9F.png)
我能够使用以下提示提取元数据:
wmic datafile where name="Q:\\filename.docx" list full
我可以使用此提示查看文件或文件夹的所有者:
dir øa /q
但我想提取右键单击文件并转到“属性”>“详细信息”>“来源”时列出的信息,例如文件的作者、最后保存者、所有者、创建者。
知道如何对文件夹中的所有文件执行此操作,而不是一次手动执行一个文件吗?谢谢!
答案1
我发现了一个很棒的 powershell 函数这里:
# ----------------------------------------------------------------------------- # Script: Get-FileMetaDataReturnObject.ps1 # Author: ed wilson, msft # Date: 01/24/2014 12:30:18 # Keywords: Metadata, Storage, Files # comments: Uses the Shell.APplication object to get file metadata # Gets all the metadata and returns a custom PSObject # it is a bit slow right now, because I need to check all 266 fields # for each file, and then create a custom object and emit it. # If used, use a variable to store the returned objects before attempting # to do any sorting, filtering, and formatting of the output. # To do a recursive lookup of all metadata on all files, use this type # of syntax to call the function: # Get-FileMetaData -folder (gci e:\music -Recurse -Directory).FullName # note: this MUST point to a folder, and not to a file. # ----------------------------------------------------------------------------- Function Get-FileMetaData { <# .Synopsis This function gets file metadata and returns it as a custom PS Object .Description This function gets file metadata using the Shell.Application object and returns a custom PSObject object that can be sorted, filtered or otherwise manipulated. .Example Get-FileMetaData -folder "e:\music" Gets file metadata for all files in the e:\music directory .Example Get-FileMetaData -folder (gci e:\music -Recurse -Directory).FullName This example uses the Get-ChildItem cmdlet to do a recursive lookup of all directories in the e:\music folder and then it goes through and gets all of the file metada for all the files in the directories and in the subdirectories. .Example Get-FileMetaData -folder "c:\fso","E:\music\Big Boi" Gets file metadata from files in both the c:\fso directory and the e:\music\big boi directory. .Example $meta = Get-FileMetaData -folder "E:\music" This example gets file metadata from all files in the root of the e:\music directory and stores the returned custom objects in a $meta variable for later processing and manipulation. .Parameter Folder The folder that is parsed for files .Notes NAME: Get-FileMetaData AUTHOR: ed wilson, msft LASTEDIT: 01/24/2014 14:08:24 KEYWORDS: Storage, Files, Metadata HSG: HSG-2-5-14 .Link Http://www.ScriptingGuys.com #Requires -Version 2.0 #> Param([string[]]$folder) foreach($sFolder in $folder) { $a = 0 $objShell = New-Object -ComObject Shell.Application $objFolder = $objShell.namespace($sFolder) foreach ($File in $objFolder.items()) { $FileMetaData = New-Object PSOBJECT for ($a ; $a -le 266; $a++) { if($objFolder.getDetailsOf($File, $a)) { $hash += @{$($objFolder.getDetailsOf($objFolder.items, $a)) = $($objFolder.getDetailsOf($File, $a)) } $FileMetaData | Add-Member $hash $hash.clear() } #end if } #end for $a=0 $FileMetaData } #end foreach $file } #end foreach $sfolder } #end Get-FileMetaData
然后你可以从 Powershell 尝试:
Get-FileMetaData "Parent folder" | where {$_.name -eq "filename"}
并使用 过滤属性Select-Object
。