KeithPawson I tried the same snippet in my environment and think I found the issue. It has $r as an object with multiple properties, then trying to compare that entire object to 38600. It should be $r.MessageSize -gt "38600" but even that is a little off because the MessageSize property is a string something like this "55.56 MB (58,263,782 bytes)." Here's another snippet that's a little more drawn out with more explanatory variable names. It will also take the MessageSize property, get only the number of bytes, convert those bytes to KB, and then try the comparison operation against "38600". This worked for me in my environment
$collection = @()
$publicFolders = Get-PublicFolder \ -Recurse -ResultSize unlimited
$publicFolders | ForEach-Object {
$pf = $_
$pfItemStats = Get-PublicFolderItemStatistics -Identity $pf.EntryID
$pfItemStats | ForEach-Object {
$messageSizeBytes = if ($_.MessageSize -match '.+\((.+) bytes\)') { $Matches[1].Replace(',', '') }
$messageSizeKB = $messageSizeBytes / 1KB
if ($messageSizeKB -gt '38600') {
$itemInfo = $_ | Select-Object @{n = 'PublicFolderName'; e = { $pf.Identity } }, ItemType, Subject, MessageSize, HasAttachments, CreationTime, LastModificationTime
$collection += $itemInfo
$itemInfo
}
}
}
$collection | Format-Table -AutoSize
Edit: revised this so the PublicFolderName is the actual name of the public folder instead of the EntryId for the public folder.