If you have file servers, you most likely run user quotas. Not running quotas would allow users to quickly fill up the entire drive. Quota’s are no guarantee of smooth sailing though. One of our file servers got down to 10% free space. In the same way that Social Security over promises benefits, we over allocated quotas. Too many users and not enough pie! There has to be a better way to manage the File Server Resource Manager quota email because it has some problems that I didn’t like.
With a bit of PowerShell – that old report can be extended. Here is how I wanted to extend it:
- Be able to clearly see what users were at a warning limit (and to be able to lower/raise) the reporting level
- Automate reporting to administrators
- Alert users who reach a warning level
- Allows users to easily delete “low hanging fruit”
Still interested? Well, here is the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
Add-PSSnapin Quest.ActiveRoles.ADManagement Set-Location "C:\Users\Public\Scripts\GetUserQuota\" $Date = (get-date).adddays(-1) $Users = Get-EventLog -ComputerName SERVERNAME -LogName System -Source ntfs -after $Date | where {$_.eventID -eq 36} | Select-Object Username -Unique | Sort-Object Username $emailFrom = "EMAIL@DOMAIN.COM" $subject = "Your Largest Files" $smtpServer = "MAILSERVER" Remove-Item "C:\users\public\Scripts\GetUserQuota\Output\*.*" -Force Foreach ($User in $Users) { $Name = $User.UserName.TrimStart("DOMAINNAME") $emailto = get-qaduser $Name | Select-Object email | out-string $body = "You are receiving this email because your U drive is nearly full. The attached document ($Name.TXT) lists your 30 largest files. If these files are not needed, please delete them and empty your Recycle Bin." $Directory= "DIRECTORY" Get-ChildItem $Directory -recurse -file | ? {$($_ | Get-Acl).Owner -match $name } | Sort-Object length -Descending | Select-Object Directory,Name -first 30 | format-table -AutoSize | Out-String -Width 4096 | Out-file ".\Output\$name.txt" Send-MailMessage -to $emailto -from $emailFrom -Subject $subject -Body $body -Attachments ".\Output\$name.txt", ".\Managing Your Files.pptx" -SmtpServer $smtpServer } |
Here is what the email looks like:
A few other notes about this script:
- Be sure to change anything in all CAPS to fit your environment. EX: “DIRECTORY” to “\\SERVER\SHARE\”
- While we attach the largest 30 files that belong to a user, we also attach a second PowerPoint that shows how to find other large files/unused files. If you are interested in that PowerPoint, you can download it from here.
Note: This article has been updated for Server 2008 R2 and Server 2012/2012R2: You can read it here.
Script works good for me. I am interested in the PowerPoint.
Thanks
Brad
Thanks Brad – here is that link: http://DeployHappiness.com/wp-content/uploads/2014/11/Managing-Your-Files.pptx
Also – check out the updated version of this article: http://deployhappiness.com/delete-old-files-with-file-management-tasks/
Good day,
Are you able to assist me with a script to retrieve quota that I have setup on file server resource management, then email the users that have exceeded the quota specified in that quota.
All email addresses for users are in active directory
I would like to run the script as a scheduled task daily.
Thanks
Christopher Calverey
That script in this post should do that! Are you having issues with it?