locked
Help With EMS Script for Mailbox Usage RRS feed

  • Question

  • I wonder if someone could point me in the right direction for a script I'd like which would grab a users's TotalItemSize, then compare it to their IssueWarningQuota and present the result as a percentage.  Something along the lines of "User is using 90% of quota (900MB/1000MB)"

    I can get the raw numbers with Get-MailboxStatistics and Get-Mailbox, but I'm not sure how to use mathmatical functions in powershell to do the math.

    Thanks


    Friday, May 27, 2011 2:30 PM

Answers

  • Those quota and itemsize values aren't very math friendly.  There may be easier ways, but this is what I came up with:

    $usedmb = (get-mailboxstatistics $user).totalitemsize
    $usedmb -match ".+\((.+)\)" > $nul
    $usedbytes = $usedmb -replace "[^\d]"

    $quotamb = (get-mailbox $user).prohibitsendquota
    $quotamb -match ".+\((.+)\)" > $nul
    $quotabytes = $quotamb -replace "[^\d]"


    $pct_used = [int](($usedbytes / $quotabytes) * 100)

     


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    Friday, May 27, 2011 3:08 PM

All replies

  • This isn't trivial for a general script because you also have to look at the UseDatabaseQuotaDefaults property to see if the quota value from the mailbox database applies or the one from the mailbox applies.  Maybe someday I'll write one that I can share with you, but right now I haven't done that.

    Seriously, you shouldn't post to a list asking someone to write a script for you.  Few of us have time to develop scripts and give them away for free; it's enough that we share our expertise for free.  Instead you should learn how to write it yourself, and then if you have problems, post for help with the problems and show what you have developed.


    Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."
    Friday, May 27, 2011 2:55 PM
  • Those quota and itemsize values aren't very math friendly.  There may be easier ways, but this is what I came up with:

    $usedmb = (get-mailboxstatistics $user).totalitemsize
    $usedmb -match ".+\((.+)\)" > $nul
    $usedbytes = $usedmb -replace "[^\d]"

    $quotamb = (get-mailbox $user).prohibitsendquota
    $quotamb -match ".+\((.+)\)" > $nul
    $quotabytes = $quotamb -replace "[^\d]"


    $pct_used = [int](($usedbytes / $quotabytes) * 100)

     


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    Friday, May 27, 2011 3:08 PM