PowerShell Efficiencies

This topic contains 2 replies, has 2 voices, and was last updated by  Russell Keith 3 years, 9 months ago.

  • Author
    Posts
  • #11041

    Russell Keith
    Participant

    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"}

    Thanks,
    Russell

  • #11042

    Don Jones
    Keymaster

    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

    Russell Keith
    Participant

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

You must be logged in to reply to this topic.