To get and set File Server Resource Manager NTFS quota, you now have to use PowerShell's FileServerResourceManager cmdlets. In the past, I used to get and set NTFS directory quota with the dirquota command, which is deprecated. A behavioral change for me (and you?) I can live with: it's pretty easy to get directory information with Get-FsrmQuota and change dirquota using Set-FsrmQuota.

Dirquota.exe: list and modify quota the old fashioned way on Windows Server

As you may remember, the dirquota.exe command came with the File Server Resource Manager in Windows Server 2003 R2. This dirquota tool lets you get and set directory quota in Windows. Before this, the only quota possible was an user-based disk quota.

The command to list a directory quota is:

C:\>dirquota Quota List /Path:d:\www\example.com

This tool is deprecated and may be removed in future releases of Windows. Please
 use the Windows PowerShell cmdlets in the FileServerResourceManager module to a
dminister File Server Resource Manager functionality.
Quotas on machine SERVER-01:

Quota Path:             d:\www\example.com
Description:            None
Share Path:             \\SERVER-01\www\example.com
Source Template:        None
Quota Status:           Enabled
Limit:                  13.00 GB (Hard)
Used:                   6.00 GB (46%)
Available:              7.00 GB
Peak Usage:             6.00 GB (4/7/2015 1:45 PM)
Thresholds:             None

And to modify this quota to 15 GB, with dirquota:

C:\>dirquota Quota Modify /Path:d:\www\example.com /Type:Hard /Limit:15gb

The dirquota Quota List command output reports this tool as being deprecated:

This tool is deprecated and may be removed in future releases of Windows. Please use the Windows PowerShell cmdlets in the FileServerResourceManager module to administer File Server Resource Manager functionality.

So now we have to use PowerShell cmdlets.

FileServerResourceManager PowerShell cmdlets

Dirquota is replaced by the PowerShell FileServerResourceManager cmdlets. The cmdlets to use are Get-FsrmQuota and Set-FsrmQuota, for getting and setting quota through Powershell.

Another example for you, now with PowerShell:

PS C:\> Get-FsrmQuota -Path "d:\www\example.com"


Description     :
Disabled        : False
MatchesTemplate : False
Path            : d:\www\example.com
PeakUsage       : 10158080
Size            : 3758096384
SoftLimit       : False
Template        :
Threshold       :
Usage           : 10158080
PSComputerName  :
PS C:\> Set-FsrmQuota -Path "d:\www\example.com" -Size 4.5GB

The latter changed the quota to 4.5 GB:

PS C:\> Get-FsrmQuota -Path "d:\www\example.com"
[...]
Size            : 4831838208
[...]

Get-FsrmQuota quotum size in GB:

To get the quotum size of a directory in GB you'll need to convert bytes to GB. Use an Select-Object Expression for this:

# display the output of Get-FsrmQuota quotum size in GB rather than KB
Get-FsrmQuota -Path "d:\www\example.com" | Format-Table Path, @{Label="Usage GB"; Expression={$($_.size/1GB) -as [int] }} -auto
# the following lists disk quota usage in GB, using a similar Expression
Get-FsrmQuota | Sort-Object Usage -descending | Format-Table Path, @{Label="Usage GB"; Expression={[math]::Round($($_.usage/1GB),2) }} -auto

Get all quotas on the server

The Get-FsrmQuota cmdlet gets all quotas on the server when no path is provided with -Path:

PS D:\www> Get-FsrmQuota

Description     :
Disabled        : False
MatchesTemplate : False
Path            : d:\www\example.com
PeakUsage       : 284911616
Size            : 8589934592
SoftLimit       : False
Template        :
Threshold       :
Usage           : 284878848
PSComputerName  :

Description     :
Disabled        : False
MatchesTemplate : False
Path            : d:\www\example.org
PeakUsage       : 577258496
Size            : 8589934592
SoftLimit       : False
Template        :
Threshold       :
Usage           : 577249280
PSComputerName  :

Description     :
Disabled        : False
MatchesTemplate : False
Path            : d:\www\example.net
PeakUsage       : 4179968
Size            : 8589934592
SoftLimit       : False
Template        :
Threshold       :
Usage           : 4179968
PSComputerName  :

Description     :
Disabled        : False
MatchesTemplate : False
Path            : d:\www\example2.com
PeakUsage       : 86039552
Size            : 2147483648
SoftLimit       : False
Template        :
Threshold       :
Usage           : 85994496
PSComputerName  :
[...]

This makes it easy for you to script your own PowerShell File System Resource Manager Quota provisioning system, or to find users / directories with excessive disk usage.

An example is if you want to easily list all Paths and their quota usage, use Get-FsrmQuota with Select-Object and optionally Sort-Object:

Get-FsrmQuota | Select-Object Path, Usage | Sort-Object Usage
Get-FsrmQuota | Select-Object Path, Usage

But can you find large files in a directory? No, unfortunately you cannot.

The New-FsrmQuota cmdlet creates a File Server Resource Manager (FSRM) quota on the server. The quota applies to the directory and all its subdirectories (recursively). Quotas that you specify on folders higher in the heirarchy further restrict the quota specified on a folder. The Get-FsrmQuota cmdlet gets a File Server Resource Manager (FSRM) quota or all FSRM quotas on the server. The Set-FsrmQuota cmdlet changes configuration settings for a File Server Resource Manager (FSRM) quota on the server.

To find large files in directories, you need to use Get-ChildItem cmdlet, which replicates and extends the DIR command.

Here's an example:

Find the X largest files in a folder

This Technet blog article explains how to find the X largest files in a directory:

$directory = "."
Get-ChildItem $directory -Recurse `
 | Sort-Object length -Descending `
 | Select-Object -First 32 `
 | ft name,length -wrap –auto

This may come in handy when you need to find large files on your filesystem because you ran out of directory quota space... ;-)

The command will return the file names and the size of the files in bytes. Useful if you want to know what 32 files are the largest in the folder $directory. Change -First 32 to the number of files you want to list.

To sum up their total size, use:

$directory = "."
$big32 = Get-ChildItem $directory -Recurse `
 | Sort-Object length -Descending `
 | Select-Object -First 32 `
 | measure-object -property length –sum
$big32.sum /1gb # or /mb
PS D:\www> $directory = "."
PS D:\www> $big32 = Get-ChildItem $directory -Recurse `
 | Sort-Object length -Descending `
 | Select-Object -First 32 `
 | measure-object -property length –sum
PS D:\www> $big32.sum /1gb
0.252976536750793
PS D:\www> $big32.sum /1mb
259.047973632813
PS D:\www>

See Get-FsrmQuota and See Set-FsrmQuota on Microsoft TechNet Script Center for more information.

Donate a cup of coffee
Donate a cup of coffee

Thank you very much! <3 ❤️

4 Comments

  1. xabi

    Hi, related to this output:
    Path Usage GB
    —- ——–
    D:\www\example.com 13
    D:\www\example.net 8
    D:\www\saotn.org 8
    D:\www\itfaq.nl 7

    Do you know if it’s possible to add this value to the output ?
    I would like to add “total usage for D:” and “total quota assigned for D:”, but I don’t know how to sum “usage GB” and “size GB” (which corresponds to quota size)

    Thanks in advance

    • Hi Xabi,
      Thank you for your comment and sorry for my late reply.

      I’m not sure I fully understand what you are trying to accomplish here. For “Total usage for D:”, you’d better use Win32_LogicalDisk and Get-CimInstance: Get-CimInstance Win32_LogicalDisk -Filter "DeviceID='D:'" | Select-Object FreeSpace, Size

      This gives you the total size of the disk and the free size in bytes that you can use in calculations. For example:

      $UsedSpace =  @{Label="Used GB"; Expression={$(($_.size-$_.freespace)/1GB) -as [int] }}
      Get-CimInstance Win32_LogicalDisk -Filter "DeviceID='D:'" | Format-Table $UsedSpace -auto

      Does this help?

  2. Anonymous

    Hi. I’m trying to generate a list of quotas in GB. I’ve tried the following code but it isn’t working: Get-FsrmQuota | Select Path, @{Expression={$([math]::Round(($_.Usage / 1GB),2));Label=”Usage_GB”} | Sort-Object Path

    This code works but it doesn’t display the size in GB.

    Any suggestions?

    Will donate $5 if a solution is found. -Thanks.

    • Hi Robert Logan,
      So https://www.experts-exchange.com/questions/29083055/How-do-I-display-the-output-of-Get-FsrmQuota-in-GB-rather-than-Kb.html didn’t give you a definitive solution, and now it’s not worth more than $5 to you?

      Maybe you can use something in the line of:

      # there is no need for [math]::Round
      PS C:\Users\janreilink> $Usage_GB = @{Label="Usage GB"; Expression={$($_.usage/1GB) -as [int] }}
      PS C:\Users\janreilink> Get-FsrmQuota | Sort-Object Usage -descending | Format-Table Path, $Usage_GB -auto

      This outputs (munged):

      Path                         Usage GB
      ----                         --------
      D:\www\example.com                 13
      D:\www\example.net                  8
      D:\www\saotn.org                    8
      D:\www\itfaq.nl                     7
      [...]`

      I used https://msdn.microsoft.com/en-us/library/microsoft.management.infrastructure.ciminstance(v=vs.85).aspx and http://www.computerperformance.co.uk/powershell/powershell_math.htm as informational references for this.

Comments are closed