Managing Filestore quotas

The FSRM is a feature of the Windows server that assists you in managing file servers. FSRM has three key features:

  • Quota management: With FSRM, you can set soft or hard quotas on volumes and folders. A soft quota allows a user to exceed an allowance, while hard quotas stop a user from exceeding an allowance. You can configure a quota with thresholds and threshold actions. If a user exceeds 65% of the quota allowance, FSRM can send an email, while at 90%, you log an event in the event log or run a program. You have different actions for different quota levels. This recipe shows how to use quotas.
  • File screening: You can set up a file screen and stop a user from saving screened files. For example, you could screen for .MP3, or FLAC files—should a user then attempt to save a file (say, jg75-02-28D1T1.flac), the file screen rejects the request and doesn't allow the user to save the file.
  • Reporting: FSRM enables you to create a wealth of storage reports that can be highly useful for management purposes.

In this recipe, you install FSRM, perform some general configuration, and then work with soft and hard quotas.

Getting ready

This recipe makes use of an email server so that FSRM can send email to the admin. To test the email-related components of this recipe, you need have an SMTP server or an email-forwarder. The resultant emails generated by this recipe were sent to SRV1, then forwarded to a free email service at https://www.sendgrid.com. With a SendGrid account in place, you can add the SMTP service to a server in your environment and then configure it to forward mail to SendGrid to then send the emails onward.

How to do it...

  1. Install the FSRM feature:
    $IHT = @{
      Name                   = 'FS-Resource-Manager' 
      IncludeManagementTools = $True
    }
    Install-WindowsFeature @IHT
  2. Set the SMTP settings in FSRM:
    $MHT = @{
      SmtpServer        = 'SRV1.Reskit.Org'   # Previously setup 
      FromEmailAddress  = '[email protected]'
      AdminEmailAddress = '[email protected]'
    }
    Set-FsrmSetting @MHT
  3. Send a test email to check the setup:
    $MHT = @{
      ToEmailAddress = '[email protected]'
      Confirm        = $false
    }
    Send-FsrmTestEmail @MHT
  4. Create a new FSRM quota template for a 10 MB quota:
    $QHT1 = @{
      Description = 'Quota of 10MB'
      Name        = 'TenMB Limit'  
      Size        = 10MB
    }
    New-FsrmQuotaTemplate @QHT1
  5. Create another quota template for a quota of 5 MB:
    $QHT2 = @{
      Name        = 'Soft 5MB Limit'
      Description = 'Soft Quota of 5MB'
      Size        = 5MB
      SoftLimit   = $True
    }
    New-FsrmQuotaTemplate @QHT2
  6. View the available FSRM quota templates:
    Get-FsrmQuotaTemplate |
      Format-Table -Property Name, Description, Size, SoftLimit
  7. Create two new folders on which to place quotas:
    If (-Not (Test-Path C:Quota)) {
      New-Item -Path C:Quota -ItemType Directory  |
        Out-Null
    }
    If (-Not (Test-Path C:QuotaS)) {
      New-Item -Path C:QuotaS -ItemType Directory  |
        Out-Null
    }
  8. Create an FSRM action for when the threshold is exceeded:
    $Body = @'
    User [Source Io Owner] has exceeded the [Quota Threshold]% quota threshold for the quota on [Quota Path] on server [Server].  
    The quota limit is [Quota Limit MB] MB, and [Quota Used MB] MB 
    currently is in use ([Quota Used Percent]% of limit).
    '@
    $NAHT = @{
    Type      = 'Email'
    MailTo    = '[email protected]'
    Subject   = 'FSRM Over limit [Source Io Owner]'
    Body      = $Body
    }
    $Action1 = New-FsrmAction @NAHT
  9. Create an FSRM action for when the soft threshold is exceeded:
    $Thresh = New-FsrmQuotaThreshold -Percentage 85 -Action $Action1
  10. Create a soft 10 MB quota on the C:Quotas folder with a threshold:
    $NQHT1 = @{
      Path      = 'C:QuotaS'
      Template  = 'Soft 5MB Limit'
      Threshold = $Thresh
    }
    New-FsrmQuota @NQHT1
  11. Now test the 85% soft quota limit on C:QuotaS:
    Get-ChildItem c:quotas -Recurse | Remove-Item -Force
    $S = '42'
    1..24 | foreach {$s = $s + $s}
    $S | Out-File -FilePath C:QuotaSDemos.txt
    Get-ChildItem -Path C:QuotaSDemos.txt
  12. Check if you received a notification email via Outlook or another mail client.
  13. Create a second threshold action to log to the application log:
    $Action2 = New-FsrmAction -Type Event -EventType Error
    $Action2.Body = $Body
  14. Create two quota thresholds for a new quota:
    $Thresh2 = New-FsrmQuotaThreshold -Percentage 65 
    $Thresh3 = New-FsrmQuotaThreshold -Percentage 85 
    $Thresh2.Action = $Action2
    $Thresh3.Action = $Action2  # same action details 
  15. Create a hard quota, with two thresholds and related threshold actions, based on an FSRM quota template:
    $NQHT = @{
    Path        = 'C:Quota'
    Template    = 'TenMB Limit'
    Threshold   =  ($Thresh2, $Thresh3)
    Description = 'Hard Threshold with2 actions'
    }
    New-FsrmQuota @NQHT 
  16. Remove existing files, if any:
    Get-ChildItem C:Quota -Recurse | Remove-Item -Force
  17. Test a hard limit on C:Quota from a different user:
    $URK = "[email protected]"
    $PRK = ConvertTo-SecureString 'Pa$$w0rd' -AsPlainText -Force
    $CredRK = New-Object system.management.automation.PSCredential $URK,$PRK
    $SB = {
      $S = '42'
      1..27 | foreach {$s = $s + $s}
      $S | Out-File -FilePath C:QuotaDemos.Txt -Encoding ascii
      $Len = (Get-ChildItem -Path C:QuotaDemos.Txt).Length}
    $ICMHT = @{
      ComputerName = 'SRV1'
      Credential   = $CredRK
      ScriptBlock  = $SB}
    Invoke-Command @ICMHT
  18. View the event log entries related to the overuse of the quota:
    Get-EventLog -LogName Application -Source SRMSVC  | 
      Format-Table -AutoSize -Wrap

How it works…

In step 1, you install the FSRM feature on SRV1, which looks like this:

How it works…

In step 2, you set SMTP server settings for FSRM, which generates no output. The assumption is that you've configured SRV1 to be an email forwarder, forwarding mail to SendMail.Com for onward transmission. This step produces no output.

In step 3, you test the SMTP service by using the Send-FsrmTestEmail cmdlet. There's no output as such from this step, but the resultant email looks like this:

How it works…

With step 4, you create an FSRM quota template, which looks like this:

How it works…

In step 5, you create an additional FSRM quota template, this time for 5 MB, which looks like this:

How it works…

In step 6, you review the FSRM templates available on SRV1. This includes templates added when you installed the FSRM feature, plus the ones you created in step 4 and step 5. The available templates look like this:

How it works…

In step 7, you create two new folders on SRV1 to assist in testing soft and hard Filestore quotas. In step 8 and step 9, you create two new FSRM quota-exceeded actions. These three steps produce no output.

In step 10, you create a new soft quota on C:QuotaS, which looks like this:

How it works…

In step 11, you test the soft quota by building a large string and outputting the string to a file that exceeds the soft quota. The output from this step is as follows:

How it works…

Exceeding the soft quota generates an email message, which looks like this:

How it works…

In step 13, you create a second threshold action to log to the application event log. In step 14, you create two new FSRM quota thresholds (for 65% of the quota exceeded, and 85% of the quota exceeded). These two steps produce no output.

In step 15, you create a hard quota for C:Quota, which has the two threshold actions you set in the two previous steps. The output from this step looks like this:

How it works…

In step 16, you remove any existing files in C:Quota, which produces no output. In step 17, you test the hard quota, which looks like this:

How it works…

Finally, in step 18, you view the Application log events that FSRM logged when the two quota thresholds were exceeded (that is, when the quota threshold exceeded 65% and 85%). The output looks like this:

How it works…

There's more...

In this recipe, you set up and tested both a soft and a hard FSRM quota. With the soft quota, you configured FSRM to send an email to inform the recipient that a quota has been exceeded. With the hard quota, you logged two event-log messages (when the quota has been exceeded by 65% and 85%). While the soft quota means a user can exceed the quota, with a hard quota, the user can only save up to the quota limit. As you can see in step 17, the file saved in C:Quota was limited to just 10 MB.

The quotas set in this recipe were extremely small and would probably not be of much use in production. But a simple change from, say, 10 MB to 10 GB, would be simple to make.

Also, for the soft quota, the quota exceeded the action results in the email being sent, while for the hard quota, FSRM just writes Application event-log entries. In production, you might want to send email to either or both an administrator and the user who has exceeded the quota thresholds.

In step 14, you create two quota thresholds (one invoked at 65%, and the second at 85%). For both thresholds, you apply the same text, which gets posted when either threshold is exceeded. You can see these two messages in step 18.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.192.183