You are here:
ActiveXperts.com > ActiveXperts Network Monitor > WindowsManagement > Scripts > Disks and File Systems > Disk Quotas
Quicklinks
NOTE: ActiveXperts Network Monitor ships with a large collection of VBScript scripts to monitor any aspect of your network. Most VBScript scripts also have a PowerShell implementation. Download Now »
Set colDiskQuotas = CreateObject("Microsoft.DiskQuota.1")
colDiskQuotas.Initialize "C:\", True
set objUser = colDiskQuotas.AddUser("jsmith")
set objUser = colDiskQuotas.FindUser("jsmith")
objUser.QuotaLimit = 50000000
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
Set colDiskQuotas = CreateObject("Microsoft.DiskQuota.1")
colDiskQuotas.Initialize "C:\", True
set objUser = colDiskQuotas.FindUser("jsmith")
colDiskQuotas.DeleteUser(objUser)
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
Const ENABLE_QUOTAS = 2
Set colDiskQuotas = CreateObject("Microsoft.DiskQuota.1")
colDiskQuotas.Initialize "C:\", True
colDiskQuotas.QuotaState = ENABLE_QUOTAS
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
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 "DefaultLimit: " & vbTab & objQuotaSetting.DefaultLimit
Wscript.Echo "DefaultWarningLimit: " & vbTab & _
objQuotaSetting.DefaultWarningLimit
Wscript.Echo "ExceededNotification: " & vbTab & _
objQuotaSetting.ExceededNotification
Wscript.Echo "State: " & vbTab & objQuotaSetting.State
Wscript.Echo "VolumePath: " & vbTab & objQuotaSetting.VolumePath
Wscript.Echo "WarningExceededNotification: " & vbTab & _
objQuotaSetting.WarningExceededNotification
Next
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
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
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: "& vbTab & objQuota.QuotaVolume
Wscript.Echo "User: "& vbTab & objQuota.User
Wscript.Echo "Disk Space Used: "& vbTab & objQuota.DiskSpaceUsed
Next
Set colDiskQuotas = CreateObject("Microsoft.DiskQuota.1")
colDiskQuotas.Initialize "C:\", True
set objUser = colDiskQuotas.FindUser("jsmith")
objUser.QuotaThreshold = 90000000
objUser.QuotaLimit = 100000000