I am exported a directory scan from TreeSize. The CSV looks like this:
TreeSize Report, 2/15/2024 10:50 AM
E:\Folder\Users\ on [Data] - Filter: Name does not equal "~snapshot"
Drive: E:\ Size: 1992277.0 MB Used: 850815.5 MB Free: 1141461.5 MB
Name,Path,Allocated,Files,Folders
"E:\Folder\Users\ on [Data]","E:\Folder\Users\",556110.0 MB,795745,81199
"UserA","E:\Folder\Users\UserA\",16471.4 MB,10224,933
"UserB","E:\Folder\Users\UserB\",4408.3 MB,2642,184
"UserC","E:\Folder\Users\UserC\",704.5 MB,848,97
"UserD","E:\Folder\Users\UserD\",9440.0 MB,19158,813
I am trying to have a script that checks the group "users-group" and for each member of that group, it finds the corresponding user in the TreeSize CSV and adds the Allocated, Files, Folders value to an email that it then sends out.
This is the script I currently have:
$recipients = "admin@domain.local"
$sender = "Users-Group@domain.local"
$subject = "User Report"
$groupMembers = Get-ADGroupMember -Identity "users-group" -Recursive | Get-ADUser -Properties displayName, Mail, homeDirectory, Department | Select-Object displayName, Mail, homeDirectory, Department
$treeSizeReport = Import-Csv "\\domain.local\dfs\Share\Scripts\Datafiles\TreeSize-Report.csv" # Combine the information from the two sources
$combinedData = foreach ($user in $groupMembers) {
$matchingRow = $treeSizeReport | Where-Object { $_.Name -eq $user.displayName }
[PSCustomObject]@{
DisplayName = $user.displayName
Mail = $user.Mail
HomeDirectory = $user.homeDirectory
Department = $user.Department
Allocated = $matchingRow.Allocated
Files = $matchingRow.Files
Folders = $matchingRow.Folders
}
}
# Sort the combined data by DisplayName
$sortedData = $combinedData | Sort-Object DisplayName
# Convert to HTML for email body
$body = $sortedData | ConvertTo-Html | Out-String
# Send email
Send-MailMessage -To $recipients -From $sender -Subject $subject -Body $body -BodyAsHtml -SmtpServer "smtp.domain.local"
Unfortunately, the script is not working correctly and the Allocated, Files, and Folders values are not being added to the email. I am not sure what is wrong. Any help would be greatly appreciated.