Enumerating Disk Quotas

Microsoft® Windows® 2000 Scripting Guide

The DiskQuotaControl enables you to enumerate the quota entries for a particular volume. You can use this object to determine the quota and warning limit established for each user, the amount of disk space currently charged to the user, and whether the user has exceeded his or her quota level. Key user-related properties of the DiskQuotaControl are shown in Table 10.7.

Table 10.7 DiskQuotaControl Properties Related to Individual Users

Property

Description

AccountStatus

Status of the user account. Values are:

0 - Account is valid.

1 - Account information is unavailable.

2 - Account has been deleted.

3 - Account is invalid.

4 - Account cannot be found.

5 - Account information cannot be resolved.

DisplayName

Full name of the user associated with the quota entry (for example, Ken Myer). Values will be displayed only for local user accounts.

ID

Unique ID number assigned to the quota entry.

LogonName

User name of the user associated with the quota entry (for example, kmyer).

QuotaLimit

Quota limit (in bytes) set for this particular user. A value of -1 means that no limit has been set for the user.

QuotaThreshold

Warning limit (in bytes) set for this particular user. A value of -1 means that no limit has been set for the user.

QuotaUsed

Current number of bytes currently in use by this particular user.

Scripting Steps

Listing 10.12 contains a script that enumerates the disk quota entries on a computer. 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 returns 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, QuotaLimit, QuotaThreshold, and QuotaUsed properties.

Listing 10.12 Enumerating Disk Quotas

  
1
2
3
4
5
6
7
8
Set colDiskQuotas = CreateObject("Microsoft.DiskQuota.1")
colDiskQuotas.Initialize "C:\", True
For Each objUser in colDiskQuotas
 Wscript.Echo "Logon name: " & objUser.LogonName
 Wscript.Echo "Quota limit: " & objUser.QuotaLimit
 Wscript.Echo "Quota threshold: " & objUser.QuotaThreshold
 Wscript.Echo "Quota used: " & objUser.QuotaUsed
Next

Issuing Disk Quota Alerts

When a user reaches his or her quota warning level, an event is recorded in the System event log on the computer where the quota violation occurred. However, no notice of any kind is issued to the user. Users do not know that they are reaching their quota limit unless an administrator periodically scans the event log for quota violations and then issues a warning. Without such notices, users will find out they have reached their quota limit only when they attempt to save a file and are denied access because they have run out of disk space.

Because of this, you might want to create a script that periodically checks to see which users, if any, are over their warning limit and then issues an alert (such as an e-mail message).