Enumerating Disk Space by User

Microsoft® Windows® 2000 Scripting Guide

Tracking disk space use by user is an important administrative task. It helps ensure that users are allocated sufficient disk space, and it also ensures that no single user takes up a disproportionate share of the available space.

If you use NTFS disk quotas, NTFS tracks the amount of disk space consumed by each user on a volume. To gain a better understanding of how disk space is being apportioned on a computer, you can enable disk quotas on a volume and allow NTFS to enumerate disk space use by user. After quotas have been enabled, you can retrieve the disk space use enumeration by using the DiskQuotaControl Automation object. This use of this object is explained in more detail in the "Managing Disk Quotas on the NTFS File System" section of this chapter.

tip Tip

  • Enabling disk quotas does not mean you have to limit the amount of disk space available to users. If you are primarily concerned with assessing disk space use, enable quotas but allocate each user an unlimited amount of disk space. Alternatively, you can enable quotas, retrieve an NTFS-generated disk space use report, and then disable the quotas again.

Scripting Steps

Listing 10.7 contains a script that uses disk quotas to enumerate disk space use by user. To carry out this task, the script must perform the following steps:

  1. Create an instance of the DiskQuota1 object.

  2. Use the Initialize method to indicate that the new quota entry should be added to drive C. This will return a collection of all users with disk quota entries on drive C.

    The Initialize method requires the following two parameters:

    • The drive letter of the drive where quotas are being enumerated (in this case, C).

    • The value True, indicating that the drive should be initialized for read/write access. By setting this value to False, you can enumerate disk quota entries on the volume but you cannot make any changes (read-only).

  3. For each user in the collection of disk quota entries, echo the values of the LogonName and QuotaUsed properties.

Listing 10.7 Using Disk Quotas to Enumerate Disk Space by User


Set colDiskQuotas = CreateObject("Microsoft.DiskQuota.1")
colDiskQuotas.Initialize "C:\", True
For Each objUser in colDiskQuotas
 Wscript.Echo "Logon name: " & objUser.LogonName
 Wscript.Echo "Quota used: " & objUser.QuotaUsed