The FSRM is a feature of the Windows server that assists you in managing file servers. FSRM has three key features:
jg75-02-28D1T1.flac
), the file screen rejects the request and doesn't allow the user to save the file.In this recipe, you install FSRM, perform some general configuration, and then work with soft and hard quotas.
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.
$IHT = @{ Name = 'FS-Resource-Manager' IncludeManagementTools = $True } Install-WindowsFeature @IHT
$MHT = @{ SmtpServer = 'SRV1.Reskit.Org' # Previously setup FromEmailAddress = '[email protected]' AdminEmailAddress = '[email protected]' } Set-FsrmSetting @MHT
$MHT = @{ ToEmailAddress = '[email protected]' Confirm = $false } Send-FsrmTestEmail @MHT
$QHT1 = @{ Description = 'Quota of 10MB' Name = 'TenMB Limit' Size = 10MB } New-FsrmQuotaTemplate @QHT1
$QHT2 = @{ Name = 'Soft 5MB Limit' Description = 'Soft Quota of 5MB' Size = 5MB SoftLimit = $True } New-FsrmQuotaTemplate @QHT2
Get-FsrmQuotaTemplate | Format-Table -Property Name, Description, Size, SoftLimit
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 }
$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
$Thresh = New-FsrmQuotaThreshold -Percentage 85 -Action $Action1
C:Quotas
folder with a threshold:$NQHT1 = @{ Path = 'C:QuotaS' Template = 'Soft 5MB Limit' Threshold = $Thresh } New-FsrmQuota @NQHT1
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
$Action2 = New-FsrmAction -Type Event -EventType Error $Action2.Body = $Body
$Thresh2 = New-FsrmQuotaThreshold -Percentage 65 $Thresh3 = New-FsrmQuotaThreshold -Percentage 85 $Thresh2.Action = $Action2 $Thresh3.Action = $Action2 # same action details
$NQHT = @{ Path = 'C:Quota' Template = 'TenMB Limit' Threshold = ($Thresh2, $Thresh3) Description = 'Hard Threshold with2 actions' } New-FsrmQuota @NQHT
Get-ChildItem C:Quota -Recurse | Remove-Item -Force
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
Get-EventLog -LogName Application -Source SRMSVC | Format-Table -AutoSize -Wrap
In step 1, you install the FSRM feature on SRV1
, which looks like this:
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:
With step 4, you create an FSRM quota template, which looks like this:
In step 5, you create an additional FSRM quota template, this time for 5 MB, which looks like this:
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:
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:
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:
Exceeding the soft quota generates an email message, which looks like this:
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:
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:
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:
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.
3.141.192.183