PowerShell Get-FsrmQuota and Set-FsrmQuota

To get and set File Server Resource Manager NTFS quota you now have to use PowerShell FileServerResourceManager cmdlets. It's pretty easy to get directory information with Get-FsrmQuota and change dirquota.exe using Set-FsrmQuota.
Published on Tuesday, 7 April 2015

From dirquota.exe to Get-FsrmQuota and Set-FsrmQuota is a behavioral change for me (and you?) I can live with.


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\example.nl
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.

Deny vulnerable WordPress plugins using Windows Server File Server Resource Manager's File Screens

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.