How to find every user's quota files in a Windows server 2003?

3

0

I have a Windows server 2003 R1 with 150 users using some folders in a disk limited by quotas. I am asking users to delete old files but it happens that they do not know which files are their own so they can delete them. How can I view a list with the owned per user files in a folder or disk? Is there a Windows Administrative tool which I can use from a Windows 7 or 8 or whatever (linux?) pc to achieve this ?

Radolino

Posted 2014-03-11T09:58:30.490

Reputation: 131

Hi Rob, are you looking for total space used per user (based on files owned)? – Fazer87 – 2014-06-27T11:04:25.900

Hi Fazer87, no I am looking for the files which are part of the user's quote. I have full permissions to do anything I want, but I can't manage to help users that see that they do not have any space left (quota used 100%). Usually they do not know which files are theirs and I cannot help them ! – Radolino – 2014-06-27T11:06:26.753

Possible duplicate on Serverfault: http://serverfault.com/questions/195945/how-to-find-files-affecting-your-disk-quota-in-windows-server-2003-or-2008

– Thomas Weller – 2014-07-01T12:18:58.907

Answers

1

A simple way to display files and owning accounts is to use the -q parameter of the dir command in a Command Prompt. A more selective display can be done via:

dir /q | find "Administrator"

To display each folder name followed by all files (if any) owned by the Administrator account, pipe the command as follows:

dir /q /s | findstr "Administrator Directory"

Another solution is via Windows Explorer : Right-click a column and choose to display Owner.

Once the Owner column is displayed, one can sort the files by the owner. Selecting files will display the total size of the selected files in the bottom panel.

One can also display only files owned by a user, by entering in the Search box (top right) the query owner:<user-name>, for example owner:administrator.

harrymc

Posted 2014-03-11T09:58:30.490

Reputation: 306 093

I tried to dir /q with my username and it did find nothing. Also AccessEnum finds groups and not users (or I am missing something). – Radolino – 2014-06-27T11:49:59.813

Try dir /q without findstr to see the exact name of the owning account. I have deleted AccessEnum from my answer, as it only displays files whose permissions differ from their parent folder (security tool). Question: What is wrong with using Windows Explorer, right-click a column and choosing to display Owner. – harrymc – 2014-06-27T12:07:33.973

Nice tip (the column one) I didn't know it exists ! But however, I need to get a list with the files per user account. And dir /q | find "myaccount" returns nothing. – Radolino – 2014-06-27T12:26:13.643

It's not possible for "dir /q" to return nothing. Could you give an example of dir /q alone without no findstr. – harrymc – 2014-06-27T13:15:27.873

it does. In my root C:\ drive, dir /q | find "username" returns empty. – Radolino – 2014-06-27T13:17:48.903

1Please enter the command "dir /q" alone exactly as written here (6 characters), without adding findstr. Otherwise what you are doing is piping the output of dir into another program called findstr. Findstr is not a parameter of the dir command but a separate command. Note: In Windows Explorer you could sort by owner and select some files to get the total size in the bottom panel. Also, once Owner is displayed, you can write in the search box (top right) the text owner:administrator to display only files with that owner. – harrymc – 2014-06-27T13:52:27.747

the "owner:administrator" is what I've been looking for and does its work 100%. You can navigate to the folder you want, enter this tag on the search bar and you get all the user's files at once! It's quite a hack for most of the people using windows.... Please change your reply or re-post in order for me to accept. Thanks. – Radolino – 2014-07-29T06:25:36.950

0

Files in a quota are determined by who owns the file. The quota usage is a sum of all files owned by user "domain\username". With this in mind, the best way to see who is abusing space, who has what in their quota etc is to enumerate all files with their size, owner and last used date.

By getting this info and exporting to CSV, you can then group the files in excel to see whats too big, whats too unused and who has a million files more than they should.

When I had to accomplish a similar task, I used teh following piece of VBS. This piece of script will prompt you for a base folder and will recurse everything under it. On completion, a CSV is created in the same folder that the script itself is in:

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

If you are wanting to help your users, I would run this overnight and then speak to a user the following day to establish what they can reduce/remove.

If you only want infor for a specific user, you can always tell the VBS to only write out on a match similar to:

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

Fazer87

Posted 2014-03-11T09:58:30.490

Reputation: 11 177

Thanks for replying but how is this going to help me ? You're posting some bits of "VBS" code? Sorry but this is a bit out of subject. I truly can't see how this will help me. – Radolino – 2014-06-27T11:28:58.510

You asked "How can I view a list with the owned per user files in a folder or disk?". Run this and it will generate you that view since its not available through windows natively! – Fazer87 – 2014-06-27T11:29:57.030

Further to this - there aren't that many good tools out there to do this except perhaps something like Treesize Pro - whereas this will give exactly the info you need in a format you can work with immediately – Fazer87 – 2014-06-27T11:32:07.400

I executed your code as a vbs file and nothing was reported. I need the path\files which belong to each user and eat up his quota. Also I don't know If treesize does that but I'll give it a go (trial). – Radolino – 2014-06-27T11:36:47.787

Is this an issue with all 150 users sharing a folder? – Joey – 2014-06-30T13:57:44.347

1It's not a "problem" but a requirement. Imagine that the quota of users fills up and they ask "Can I have some more space please". The answer is "no, please delete something from your old files". And they reply "I don't have any files, I've deleted them". I go through their quota and see that it's filled up 95% and I can't help them, because it's a huge network drive with thousands of files shared among the users ! – Radolino – 2014-06-30T18:33:34.700