我有一台 Windows Server 2003 R1,其中有 150 名用户使用受配额限制的磁盘中的某些文件夹。我要求用户删除旧文件,但他们不知道哪些文件是他们自己的,所以他们可以删除它们。我如何查看文件夹或磁盘中每个用户拥有的文件列表?是否有 Windows 管理工具,我可以从 Windows 7 或 8 或任何(Linux?)PC 上使用来实现此目的?
答案1
显示文件和所有者帐户的简单方法是使用 命令提示符中的命令-q
参数。可以通过以下方式进行更有选择性的显示:dir
dir /q | find "Administrator"
要显示管理员帐户拥有的每个文件夹名称及其后的所有文件(如果有),请按如下方式输入命令:
dir /q /s | findstr "Administrator Directory"
另一个解决方案是通过 Windows 资源管理器:右键单击某一列并选择显示Owner
。
一旦显示所有者列,就可以按所有者对文件进行排序。选择文件将在底部面板中显示所选文件的总大小。
您还可以通过在搜索框(右上角)输入查询来仅显示用户拥有的文件,owner:<user-name>
例如owner:administrator
。
答案2
配额中的文件由文件所有者决定。配额使用量是用户“域\用户名”拥有的所有文件的总和。考虑到这一点,查看谁在滥用空间、谁的配额中有什么等的最佳方法是枚举所有文件及其大小、所有者和上次使用日期。
通过获取此信息并导出为 CSV,您可以在 Excel 中对文件进行分组,以查看哪些文件太大、哪些文件太少使用以及哪些文件的数量超出应有的数量。
当我必须完成类似任务时,我使用了以下 VBS。此脚本将提示您输入基本文件夹并递归其下的所有内容。完成后,将在脚本本身所在的同一文件夹中创建一个 CSV:
on error resume next
' Flags for browse dialog
Const BIF_returnonlyfsdirs = &H0001
Const BIF_dontgobelowdomain = &H0002
Const BIF_statustext = &H0004
Const BIF_returnfsancestors = &H0008
Const BIF_editbox = &H0010
Const BIF_validate = &H0020
Const BIF_browseforcomputer = &H1000
Const BIF_browseforprinter = &H2000
Const BIF_browseincludefiles = &H4000
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objDlg = WScript.CreateObject("Shell.Application")
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
'Get the Source Folder
' Use the BrowseForFolder method.
Set objStartFolder = objDlg.BrowseForFolder (&H0, _
"Please select the FOLDER to report on.", BIF_editbox + BIF_returnonlyfsdirs)
' Here we use TypeName to detect the result.
If InStr(1, TypeName(objStartFolder), "Folder") > 0 Then
sourceFolder = objStartFolder.ParentFolder.ParseName(objStartFolder.Title).Path
Else
MsgBox "An error has occured: Unable to read destination folder"
End if
'Ask to open the report now or just close
strMbox = MsgBox("Are youn sure you want to run the report of: " & sourceFolder & chr(13) & chr(10) & chr(13) & chr(10) & "If you continue this may take an exteneded period of time, a message will be displayed when complete, continue?",4,"Are you sure?")
if strMbox = 6 Then
currentScriptPath = Replace(WScript.ScriptFullName, WScript.ScriptName, "")
reportFile = currentScriptPath & "File_Properties_Report.csv"
'OpenTextFile(destination, forwriting, createnew, open as Unicode)
Set objReportFile = objFSO.OpenTextFile(reportFile, ForWriting, True, True)
'Add headers
objReportFile.Write("Path, Size(kb), Type, Created, Last Accessed, Last Modified, Owner" & chr(13) & chr(10))
'Run though file report process
ReportFiles sourceFolder
'Close the file
objReportFile.Close
'Compete
strMbox = MsgBox("Report Complete")
End if
Function ReportFiles(currentFolder)
Dim objFolder, objFile, fileCollection, folderCollection, subFolder
Set objFolder = objFSO.GetFolder(currentFolder)
Set fileCollection = objFolder.Files
For Each objFile In fileCollection
'Get File Properties
strFilePath = objFile.Path
strFileName = objFile.Name
strFileSize = objFile.Size / 1024
strFileType = objFile.Type
strFileDateCreated = objFile.DateCreated
strFileDateLastAccessed = objFile.DateLastAccessed
strFileDateLastModified = objFile.DateLastModified
'Get File owner
strFileOwnerDomain = ""
strFileOwner = ""
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
if strFileType <> "Shortcut" or InStr(1,strFileName, "AlbumArt",1) = 0 or InStr(1,strFileName, "£",1) Then
Set colItems = objWMIService.ExecQuery ("ASSOCIATORS OF {Win32_LogicalFileSecuritySetting=""" & Replace(strFilePath, "\", "\\") & """}" & " WHERE AssocClass=Win32_LogicalFileOwner ResultRole=Owner")
For Each objItem in colItems
strFileOwnerDomain = objItem.ReferencedDomainName
strFileOwner = objItem.AccountName
Next
End If
objReportFile.Write(chr(34) & strFilePath & chr(34) & ", " _
& Round(strFileSize,2) & ", " _
& chr(34) & strFileType & chr(34) & "," _
& strFileDateCreated & "," _
& strFileDateLastAccessed & "," _
& strFileDateLastModified & "," _
& chr(34) & strFileOwnerDomain & "\" & strFileOwner & chr(34) & "," _
& chr(13) & chr(10))
Next
'Loop for each sub folder
Set folderCollection = objFolder.SubFolders
For Each subFolder In folderCollection
ReportFiles subFolder.Path
Next
End Function
如果您想帮助您的用户,我会连夜运行此操作,然后第二天与用户交谈,确定他们可以减少/删除什么。
如果您只想获取特定用户的信息,您可以随时告诉 VBS 仅写出类似以下内容的匹配项:
strTargetUser = "domain\person"
if strFileOwnerDomain & "\" & strFileOwner = strTargetUser then
objReportFile.Write(chr(34) & strFilePath & chr(34) & ", " _
& Round(strFileSize,2) & ", " _
& chr(34) & strFileType & chr(34) & "," _
& strFileDateCreated & "," _
& strFileDateLastAccessed & "," _
& strFileDateLastModified & "," _
& chr(34) & strFileOwnerDomain & "\" & strFileOwner & chr(34) & "," _
& chr(13) & chr(10))
end if