Sysadmins of the North

Technical blog, where topics include: computer, server, web, sysadmin, MySQL, database, virtualization, optimization and security

PowerShell Get-FsrmQuota and Set-FsrmQuota

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.

This may interest you:   Generate pseudo-random passwords with OpenSSL

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 expression for this:

Get-FsrmQuota -Path "d:\www\example.com" | Format-Table Path, @{Label="Usage GB"; Expression={$($_.size/1GB) -as [int] }} -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.

This may interest you:   Windows Server 2016 on Hyper-V stuck at stopping

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.

This may interest you:   Get current number of FTP client connections (NonAnonymous) with PowerShell and Get-Counter

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.

2 Comments

  1. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Snc IPDzR lx TbI JVGuNute R