PowerShell Efficiencies

Welcome Forums General PowerShell Q&A PowerShell Efficiencies

This topic contains 2 replies, has 2 voices, and was last updated by

5 years, 3 months ago.

  • Author
  • #11041

    Points: 0
    Rank: Member

    I have been watching Don's PowerShell nuggets on CBT Nugget and I know there has to be a more efficient way to get this info. It currently takes about 60 seconds to work through 975 mailboxes. I would actually prefer a nudge in the right direction (i.e. what help files to look at) instead of a full solution. I took this a full solution from somewhere and I am struggling to fully understand it. I am hoping that with a little guidance I can fully understand what is happening and be able to grow from it.

    Get-Mailbox -RecipientTypeDetails UserMailbox| Get-MailboxStatistics | where {$_.TotalItemSize -gt 1073741824}| sort-object TotalItemSize -descending |
    Add-Member -MemberType ScriptProperty -Name TotalItemSizeinMB -Value {$this.totalitemsize.value.ToMB()} -PassThru |
    Select @{Expression={$_.DisplayName};Label="User"}, @{Expression={$_.TotalItemSizeinMB};Label="Size (MB)"}, @{Expression={"{0:P0}" -f ($_.TotalItemSizeinMB/1024)};Label="Amount Over 1 GB"}


  • #11042

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    A minute for almost 1000 mailboxes? Not bad. The biggest delay is probably (a) filtering through them all to eliminate ones that aren't over your size threshold, and then (b) sorting what's left. No way to speed up either operation, really.

    That said, your Add-Member is probably unnecessary. You could add that same TotalItemSizeInMB property by just using Select-Object, although you'd add a NoteProperty with a static value, rather than a ScriptProperty that has to execute code every time you access the property. You're already adding custom properties for "User" and "Size(MB)", so I'm not sure if the "TotalItemSizeInMB" gives you any value-add.

    But you're asking PowerShell to do a lot of work... 60 seconds isn't bad.

  • #11066

    Points: 0
    Rank: Member

    Thanks for the feedback Don. I will just leave it be and move on. Thanks again.

The topic ‘PowerShell Efficiencies’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort