We’ve recently rolled out Folder Redirection and although we haven’t implemended quotas we wanted to be able to monitor the amount of space redirected folders are using on the server.

Following script generates the report in CSV format:

Name | Size(MB) | Path

and sends it to email address.

ReportUserFoldersSize.ps1:

$path = "Path_To_Folders_Root"
$EmailFrom = "Email_Address_From"
$EmailTo = "Email_Address_To"
$EmailSubject = "User Folders Report"

$SMTPServer = "SMTP_Server_IP"

Get-ChildItem $path |
Where-Object {$_.PSIsContainer} |
% {
    $size = (Get-ChildItem $_.FullName -recurse |
                Measure-Object -property length -sum).sum
    $obj = New-Object PSObject
    Add-Member -inp $obj NoteProperty Name $_.Name
    Add-Member -inp $obj NoteProperty Path $_.FullName
    Add-Member -inp $obj NoteProperty Size $size
    $obj
} | Sort-Object Size -Descending |
Select-Object Name, @{N="Size(MB)";E={"{0:N2}" -f ($_.Size / 1Mb)} },Path |
Export-CSV -Path UserFoldersReport.csv -NoTypeInformation

Send-MailMessage -To "$EmailTo" -From "$EmailFrom" -subject "$EmailSubject"
-smtpServer "$SMTPServer" -Attachments "UserFoldersReport.csv"

So for example if your user folders are located in G:\Users like ours are, set the path variable to “G:\Users”

To schedule script to run automatically use this command in Task Scheduler:

%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
-command PATH_TO_SCRIPT

Tags: ,

Leave your comment