locked
Trying to use this powershell to get mail that's "X" date and newer + mailbox quota... what am I doing wrong? RRS feed

  • Question

  • Management will periodically ask me how many mail items users have that are aging past 18 and 24 months in age.  They now want to add the get the user quota status in the same report.  I'm trying to add the Storage Limit Status to a script that I've been using for some time to get an 'old mail' report and I'm not sure if I'm doing it correctly.

    I've modified my original script to try to add the "storagelimitstatus" to is, but it doesn't report on the mailbox status, it's skipping that field in the CSV when it exports.  

    Any ideas as to a better way to add the quota limits to my original script?

    My original script to get a report from a date in the past and newer:

    $Givens =      @{n="Given Name";e={$user.FirstName}}
    $Lasts =       @{n="Last Name";e={$user.LastName}}
    $Itemsize =    @{n="Size of Items Found";e={([Microsoft.Exchange.Data.ByteQuantifiedSize]$search.ResultItemsSize).ToMb()}}
    $MailboxSize = @{n="Mailbox Size";e={$statistics.totalitemsize.value.toMB()}}
    $mailboxes = Get-mailbox -resultsize unlimited
    $mailboxes | foreach {
    $user = Get-User $_
    $statistics = get-mailboxstatistics $_
    $search = Search-Mailbox –identity $_ -searchquery ‘received:<4/1/2011 OR sent:<4/1/2011’ -estimateresultonly
    $_ | select $Givens, $Lasts, primarySMTPAddress, $ItemSize, $MailboxSize 
    } | Export-CSV -NoTypeInformation "c:\scripts\oldmail\newoldmail1.csv"

    The script I'm working on that doesn't give a quota status - note the added $StorageLimitStatus:

    $Givens =      @{n="Given Name";e={$user.FirstName}}
    $Lasts =       @{n="Last Name";e={$user.LastName}}
    $Itemsize =    @{n="Size of Items Found";e={([Microsoft.Exchange.Data.ByteQuantifiedSize]$search.ResultItemsSize).ToMb()}}
    $MailboxSize = @{n="Mailbox Size";e={$statistics.totalitemsize.value.toMB()}}
    $StorageLimitStatus = @{n="StorageLimitStatus";e={$statistics.StorageLimitStatus()}}
    $mailboxes = Get-mailbox -resultsize unlimited
    $mailboxes | foreach {
    $user = Get-User $_
    $statistics = get-mailboxstatistics $_
    $search = Search-Mailbox –identity $_ -searchquery ‘received:<4/1/2011 OR sent:<4/1/2011’ -estimateresultonly
    $_ | select $Givens, $Lasts, primarySMTPAddress, $ItemSize, $MailboxSize, $StorageLimitStatus
    } | Export-CSV -NoTypeInformation "c:\scripts\oldmail\oldmail1.csv"



    Friday, April 26, 2013 6:41 PM

Answers

  • On Fri, 26 Apr 2013 18:41:21 +0000, Brainwashed_360 wrote:
     
    >
    >
    >Management will periodically ask me how many mail items users have that are aging past 18 and 24 months in age. They now want to add the get the user quota status in the same report. I'm trying to add the Storage Limit Status to a script that I've been using for some time to get an 'old mail' report and I'm not sure if I'm doing it correctly.
    >
    >
    >
    >I've modified my original script to try to add the "storagelimitstatus" to is, but it doesn't report on the mailbox status, it's skipping that field in the CSV when it exports.
    >
    >Any ideas as to a better way to add the quota limits to my original script?
     
    StorageLimitStatus is a property, not a method, of the $statistics
    object in your script. Try removing the "()". If that doesn't work,
    try $statistics.storagelimitstatus.tostring().
     
    ---
    Rich Matheisen
    MCSE+I, Exchange MVP
     

    --- Rich Matheisen MCSE+I, Exchange MVP
    Saturday, April 27, 2013 2:01 AM

All replies

  • On Fri, 26 Apr 2013 18:41:21 +0000, Brainwashed_360 wrote:
     
    >
    >
    >Management will periodically ask me how many mail items users have that are aging past 18 and 24 months in age. They now want to add the get the user quota status in the same report. I'm trying to add the Storage Limit Status to a script that I've been using for some time to get an 'old mail' report and I'm not sure if I'm doing it correctly.
    >
    >
    >
    >I've modified my original script to try to add the "storagelimitstatus" to is, but it doesn't report on the mailbox status, it's skipping that field in the CSV when it exports.
    >
    >Any ideas as to a better way to add the quota limits to my original script?
     
    StorageLimitStatus is a property, not a method, of the $statistics
    object in your script. Try removing the "()". If that doesn't work,
    try $statistics.storagelimitstatus.tostring().
     
    ---
    Rich Matheisen
    MCSE+I, Exchange MVP
     

    --- Rich Matheisen MCSE+I, Exchange MVP
    Saturday, April 27, 2013 2:01 AM
  • Thanks for your reply Rich!  I now know who is over quota.

    Changing the line to "$statistics.storagelimitstatus.tostring()" gives me these results:

    Paste:

    "Firstname","Lastname","firstname.lastname@domain.com","0","26804","BelowLimit"
    "Firstname","Lastname","firstname.lastname@domain.com","0","0","BelowLimit"
    "Firstname","Lastname","firstname.lastname@domain.com","0","8","BelowLimit"

    etc.

    Is there a way to get the mailbox quota limit reported in the CSV after the "AboveLimit" or "BelowLimit" that you know of?

    Getting the quota setting in the results would be a big win.

    (edited for typos)
    Wednesday, May 1, 2013 8:39 PM
  • On Wed, 1 May 2013 20:39:01 +0000, Brainwashed_360 wrote:
     
    >
    >
    >Thanks for much for your reply Rich! I know know who is over quota.
    >
    >Changing the line to "$statistics.storagelimitstatus.tostring()" gives me these results:
    >
    >Paste: "Firstname","Lastname","firstname.lastname@domain.com","0","26804","BelowLimit" "Firstname","Lastname","firstname.lastname@domain.com","0","0","BelowLimit" "Firstname","Lastname","firstname.lastname@domain.com","0","8","BelowLimit" etc.
    >
    >
    >
    >Is there a way to get the mailbox quota limit reported in the CSV after the "AboveLimit" or "BelowLimit" that you know of?
    >
    >Getting the quota setting in the results would be a big win.
     
    You already have the mailbox object so it's just a matter of getting
    the quotas from that.
     
    To see the names of the properties, just do this with your mailbox:
     
    get-mailbox <name> | *quota*
     
    Then add the necessary code to your script to get the property (or
    properties) you need.
     
    ---
    Rich Matheisen
    MCSE+I, Exchange MVP
     

    --- Rich Matheisen MCSE+I, Exchange MVP
    Thursday, May 2, 2013 1:22 AM
  • Thanks Rich, your a huge help.  

    No I'm trying this as I am trying to the IssueWarningQuota and the ProhibitSendQuota to be in the results. 

    I get the same results as before, but with a no IssueWarningQuota or ProhibitSendQuota.  I could use a hand understanding what I'm doing wrong.  

    Script:

    $Givens = @{n="Given Name";e={$user.FirstName}}
    $Lasts = @{n="Last Name";e={$user.LastName}}
    $Itemsize = @{n="Size of Items Found";e={([Microsoft.Exchange.Data.ByteQuantifiedSize]$search.ResultItemsSize).ToMb()}}
    $MailboxSize = @{n="Mailbox Size";e={$statistics.totalitemsize.value.toMB()}}
    $StorageLimitStatus = @{n="StorageLimitStatus";e={$statistics.storagelimitstatus.tostring()}}
    $IssueWarningQuota = @{n="IssueWarningQuota";e={$statistics.IssueWarningQuota.tostring()}}
    $ProhibitSendQuota = @{n="ProhibitSendQuota";e={$statistics.ProhibitSendQuota.tostring()}}
    $mailboxes = Get-mailbox -resultsize unlimited
    $mailboxes | foreach {
    $user = Get-User $_
    $statistics = get-mailboxstatistics $_
    $search = Search-Mailbox –identity $_ -searchquery ‘received:<4/1/2011 OR sent:<4/1/2011’ -estimateresultonly
    $_ | select $Givens, $Lasts, primarySMTPAddress, $ItemSize, $MailboxSize, $StorageLimitStatus, $IssueWarningQuota, $ProhibitSendQuota
    } | Export-CSV -NoTypeInformation "c:\scripts\oldmail\oldmail-with-quota-attempt-3.csv"

    Results:

    "Given Name","Last Name","PrimarySmtpAddress","Size of Items Found","Mailbox Size","StorageLimitStatus","IssueWarningQuota","ProhibitSendQuota"
    "Firstname","Lastname","firstname.lastname@domain.com","0","26804","BelowLimit",,
    "Firstname","Lastname","firstname.lastname@domain.com","0","0","BelowLimit",,
    "Firstname","Lastname","firstname.lastname@domain.com","0","8","BelowLimit",,

    I've tried the script with out the ".tostring()" with the same results.  

    Anyhelp is appreciated.  

    Thursday, May 2, 2013 6:39 PM
  • On Thu, 2 May 2013 18:39:45 +0000, Brainwashed_360 wrote:
     
    >
    >
    >Thanks Rich, your a huge help.
    >
    >No I'm trying this as I am trying to the IssueWarningQuota and the ProhibitSendQuota to be in the results.
    >
    >I get the same results as before, but with a no IssueWarningQuota or ProhibitSendQuota. I could use a hand understanding what I'm doing wrong.
    >
    >
    >
    >Script: $Givens = @{n="Given Name";e={$user.FirstName}} $Lasts = @{n="Last Name";e={$user.LastName}} $Itemsize = @{n="Size of Items Found";e={([Microsoft.Exchange.Data.ByteQuantifiedSize]$search.ResultItemsSize).ToMb()}} $MailboxSize = @{n="Mailbox Size";e={$statistics.totalitemsize.value.toMB()}} $StorageLimitStatus = @{n="StorageLimitStatus";e={$statistics.storagelimitstatus.tostring()}} $IssueWarningQuota = @{n="IssueWarningQuota";e={$statistics.IssueWarningQuota.tostring()}} $ProhibitSendQuota = @{n="ProhibitSendQuota";e={$statistics.ProhibitSendQuota.tostring()}} $mailboxes = Get-mailbox -resultsize unlimited $mailboxes | foreach { $user = Get-User $_ $statistics = get-mailboxstatistics $_ $search = Search-Mailbox –identity $_ -searchquery ‘received:<4/1/2011 OR sent:<4/1/2011’ -estimateresultonly $_ | select $Givens, $Lasts, primarySMTPAddress, $ItemSize, $MailboxSize, $StorageLimitStatus, $IssueWarningQuota, $ProhibitSendQuota } | Export-CSV -NoTypeInformation
    >"c:\scripts\oldmail\oldmail-with-quota-attempt-3.csv"
    >
    >
    >
    >Results: "Given Name","Last Name","PrimarySmtpAddress","Size of Items Found","Mailbox Size","StorageLimitStatus","IssueWarningQuota","ProhibitSendQuota" "Firstname","Lastname","firstname.lastname@domain.com","0","26804","BelowLimit",,
    >"Firstname","Lastname","firstname.lastname@domain.com","0","0","BelowLimit",,
    >"Firstname","Lastname","firstname.lastname@domain.com","0","8","BelowLimit",,
    >
    >
    >
    >I've tried the script with out the ".tostring()" with the same results.
     
    The quotas are properties of the mailbox, not the
    get-mailboxstatistics results.
     
    ---
    Rich Matheisen
    MCSE+I, Exchange MVP
     

    --- Rich Matheisen MCSE+I, Exchange MVP
    Friday, May 3, 2013 1:22 AM