Disk Quota scripting
Add a Disk Quota Entry on the Local ComputerCreate a New Quota Entry
Delete a Disk Quota Entry on the Local Computer
Delete an Existing Quota Entry
Enable Disk Quotas
Enable Disk Quotas on the Local Computer
Locate A Quota Entry
List Disk Quota Entries
List Disk Quota Entries on the Local Computer
List Disk Quota Settings
List Disk Quota Settings on the Local Computer
List Disk Space by User Using Disk Quotas
List a Quota Entry
Modify a Disk Quota Entry on the Local Computer
Modify Disk Quota Settings
Modify an Existing Quota Entry
You can use any of the VBScript programs below in ActiveXperts Network Monitor. Click here for an explanation about how to include scripts in ActiveXperts Network Monitor.
Add a Disk Quota Entry on the Local Computer
Creates a custom disk quota entry for a user named kenmyer. This script must be run on the local computer.
Set colDiskQuotas = CreateObject("Microsoft.DiskQuota.1") colDiskQuotas.Initialize "C:\", True Set objUser = colDiskQuotas.AddUser("kenmyer") Set objUser = colDiskQuotas.FindUser("kenmyer") objUser.QuotaLimit = 50000000
Create a New Quota Entry
Creates a new disk quota entry for the user fabrikam\bob.
strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2" Set objAccount = objWMIService.Get _ ("Win32_Account.Domain='fabrikam',Name='bob'") Set objDisk = objWMIService.Get _ ("Win32_LogicalDisk.DeviceID='C:'") Set objQuota = objWMIService.Get _ ("Win32_DiskQuota").SpawnInstance_ objQuota.QuotaVolume = objDisk.Path_.RelPath objQuota.User = objAccount.Path_.RelPath objQuota.Limit = 10485760 objQuota.WarningLimit = 8388608 objQuota.Put_
Delete a Disk Quota Entry on the Local Computer
Deletes the disk quota entry for a user named kenmyer. This script must be run on the local computer.
Set colDiskQuotas = CreateObject("Microsoft.DiskQuota.1") colDiskQuotas.Initialize "C:\", True set objUser = colDiskQuotas.FindUser("kenmyer") colDiskQuotas.DeleteUser(objUser)
Delete an Existing Quota Entry
Deletes a disk quota entry for the user fabrikam\bob.
strDrive = "C:" strDomain = "fabrikam" strUser = "bob" strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set objQuota = objWMIService.Get _ ("Win32_DiskQuota.QuotaVolume='Win32_LogicalDisk.DeviceID=""" " & _ " & strDrive & """',User='Win32_Account.Domain=""" " & _ " & strDomain & """,Name=""" & strUser & """'") objQuota.Delete_
Enable Disk Quotas
Enables disk quotas for drive C on a computer.
Const ENFORCE_QUOTAS = 1 StrComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colDisks = objWMIService.ExecQuery _ ("Select * from Win32_QuotaSetting Where VolumePath = 'C:\\'") For Each objDisk in colDisks objDisk.State = ENFORCE_QUOTAS objDisk.Put_ Next
Enable Disk Quotas on the Local Computer
Enables disk quotas for drive C on the local computer. To enable disk quotas for a different drive, change C:\ in line two to the appropriate drive letter (for example, D:\). To disable disk quotas, set the value of the constant ENABLE_QUOTAS to 0. To enable, but not enforce, disk quotas, set this value to 1. This script must be run on the local computer.
Const ENABLE_QUOTAS = 2 Set colDiskQuotas = CreateObject("Microsoft.DiskQuota.1") colDiskQuotas.Initialize "C:\", True colDiskQuotas.QuotaState = ENABLE_QUOTAS
Locate A Quota Entry
Lists quota information for the user fabrikam\bob.
strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set objQuota = objWMIService.Get _ ("Win32_DiskQuota.QuotaVolume='Win32_LogicalDisk.DeviceID=""C:""'," & _ "User='Win32_Account.Domain=""fabrikam"",Name=""bob""'") Wscript.Echo objQuota.Limit
List Disk Quota Entries
Enumerates disk quota information (including user name, warning and quota limits, and disk space used) for each disk quota entry on a computer.
strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colDiskQuotas = objWMIService.ExecQuery("Select * from Win32_DiskQuota") For each objQuota in colDiskQuotas Wscript.Echo "Disk Space Used: " & vbTab & objQuota.DiskSpaceUsed Wscript.Echo "Limit: " & vbTab & objQuota.Limit Wscript.Echo "Quota Volume: " & vbTab & objQuota.QuotaVolume Wscript.Echo "Status: " & vbTab & objQuota.Status Wscript.Echo "User: " & vbTab & objQuota.User Wscript.Echo "Warning Limit: " & vbTab & objQuota.WarningLimit Next
List Disk Quota Entries on the Local Computer
Enumerates disk quota information (including user name, warning and quota limits, and disk space used) for each disk quota entry on the local computer.
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
List Disk Quota Settings
Enumerates the disk quota settings for each drive on a computer.
strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colQuotaSettings = objWMIService.ExecQuery _ ("Select * from Win32_QuotaSetting") For Each objQuotaSetting in colQuotaSettings Wscript.Echo "Default Limit: " & objQuotaSetting.DefaultLimit Wscript.Echo "Default Warning Limit: " & _ objQuotaSetting.DefaultWarningLimit Wscript.Echo "Exceeded Notification: " & _ objQuotaSetting.ExceededNotification Wscript.Echo "State: " & objQuotaSetting.State Wscript.Echo "Volume Path: " & objQuotaSetting.VolumePath Wscript.Echo "Warning Exceeded Notification: " & _ objQuotaSetting.WarningExceededNotification Next
List Disk Quota Settings on the Local Computer
Enumerates the disk quota settings for drive C on the local computer. To enumerate disk quota settings for a different drive, change C:\ in line two to the appropriate drive letter (for example, D:\).
Set colDiskQuotas = CreateObject("Microsoft.DiskQuota.1") colDiskQuotas.Initialize "C:\", True If colDiskQuotas.QuotaState = 2 Then Wscript.Echo "Quota state: Enabled and enforced" ElseIf colDiskQuotas.QuotaState = 1 Then Wscript.Echo "Quota state: Enabled but not enforced" Else Wscript.Echo "Quota state: Disabled" End If Wscript.Echo "Default quota limit: " & colDiskQuotas.DefaultQuotaLimit Wscript.Echo "Default warning limit: " & _ colDiskQuotas.DefaultQuotaThreshold Wscript.Echo "Record quota violations in event log: " & _ colDiskQuotas.LogQuotaLimit Wscript.Echo "Record warnings in event log: " & _ colDiskQuotas.LogQuotaThreshold
List Disk Space by User Using Disk Quotas
Uses disk quotas to report the amount of disk space being used by each individual user on a computer.
strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colQuotas = objWMIService.ExecQuery("Select * from Win32_DiskQuota") For Each objQuota in colQuotas Wscript.Echo "Volume: "& objQuota.QuotaVolume Wscript.Echo "User: "& objQuota.User Wscript.Echo "Disk Space Used: "& objQuota.DiskSpaceUsed Next
List a Quota Entry
Lists disk quota information for the user fabrikam\bob.
strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set objQuota = objWMIService.Get _ ("Win32_DiskQuota.QuotaVolume='Win32_LogicalDisk.DeviceID=""C:""'," & _ "User='Win32_Account.Domain=""fabrikam"",Name=""bob""'") Wscript.Echo objQuota.Limit
Modify a Disk Quota Entry on the Local Computer
Modifies the disk quota warning threshold and disk space limit for a user named kenmyer. This script must be run on the local computer.
Set colDiskQuotas = CreateObject("Microsoft.DiskQuota.1") colDiskQuotas.Initialize "C:\", True set objUser = colDiskQuotas.FindUser("kenmyer") objUser.QuotaThreshold = 90000000 objUser.QuotaLimit = 100000000
Modify Disk Quota Settings
Changes the warning threshold and default quota limits for drive C.
strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colQuotaSettings = objWMIService.ExecQuery _ ("Select * from Win32_QuotaSetting") For Each objQuotaSetting in colQuotaSettings objQuotaSetting.DefaultLimit = 10000000 objQuotaSetting.DefaultWarningLimit = 9000000 objQuotaSetting.Put_ Next
Modify an Existing Quota Entry
Modifies the disk quota limit for the user fabrikam\bob.
strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set objAccount = objWMIService.Get _ ("Win32_Account.Domain='fabrikam',Name='bob'") Set objDisk = objWMIService.Get("Win32_LogicalDisk.DeviceID='C:'") Set objQuota = objWMIService.Get _ ("Win32_DiskQuota.QuotaVolume= " & _ "'Win32_LogicalDisk.DeviceID=""C:""'," & _ "User='Win32_Account.Domain=""fabrikam"",Name=""bob""'") objQuota.Limit = 11111111 objQuota.Put_