Exchange 2010 suppress Get-MailboxStatistics warnings

10,406

Solution 1

I also tried $WarningActionPreference = "SilentlyContinue" --This will set all warning messages to silent. Looks like something is broken. Looks like there is a bug.

https://connect.microsoft.com/PowerShell/feedback/details/541500/warning-verbose-and-debug-streams-do-not-respect-action-preferences-the-way-they-should

Solution 2

I've been playing with this one, trying to recreate the issue (I'm on Exhcange 2007, though, so this may make a difference. I'm also pretty new to powershell). Starting with a new mailbox, "Testy McTest":

>get-variable |where { $_.Name -match "Preference" }

Name                           Value
----                           -----
ConfirmPreference              High
DebugPreference                SilentlyContinue
ErrorActionPreference          Continue
ProgressPreference             Continue
VerbosePreference              SilentlyContinue
WarningPreference              Continue
WhatIfPreference               False

I can run the following:

>Get-MailboxStatistics "Testy McTest"
WARNING: There is no data to return for the specified mailbox 'Testy McTest', because it has not been logged on to.
>Get-MailboxStatistics -WarningAction SilentlyContinue "Testy McTest"   (No Output)
>Set-Variable WarningPreference SilentlyContinue
>Get-MailboxStatistics "Testy McTest"   (No output)
>

This seems to work as normal. It might be worth mentioning that the variables for Error and Warning actions are actually ErrorActionPreference and WarningPreference. Not sure why they differ like that.

As a workaround for the specific command in the question, you could qualify the output, with something like:

>Get-MailboxStatistics |where { $_.LastLogonTime }

Which seems to list only those mailboxes that have a logon time.

Share:
10,406

Related videos on Youtube

Kev
Author by

Kev

###Actively looking for freelance work ###About Me: I'm a professional software developer and have spent my time building provisioning and web based self-service systems for IIS, Apache and Citrix XenServer, amongst other things. My Curriculum Vitae can be viewed on Stack Overflow Careers (might be a bit out of date). Stuff I like to listen to at last.fm You can get in touch here: kevin.e.kenny #@# gmail.com (you know what to do with the # and spaces). No Survey Emails Please. Also not ashamed to admit I like trains, mostly diesels, late Era 8 (BR Sectorisation) and Era 9 onwards :) I'm also interested in signalling if anyone from Network Rail is looking this far down ;)

Updated on September 17, 2022

Comments

  • Kev
    Kev over 1 year

    How do I suppress warnings from Exchange 2010's PowerShell Get-MailboxStatistics cmdlet?

    I've tried both of these options:

    Get-MailboxStatistics -WarningAction SilentlyContinue
    Get-MailboxStatistics -ErrorAction SilentlyContinue

    However I still get this warning output to the console about users that's haven't logged onto their mailboxes:

    WARNING: The user hasn't logged on to mailbox ...[snipped]..., so there is no data to return. After the user logs on, this warning will no longer appear.

    • st3v3o
      st3v3o about 13 years
      I also tried $WarningActionPreference = "SilentlyContinue" --This will set all warning messages to silent. Looks like something is broken. Looks like there is a bug. connect.microsoft.com/PowerShell/feedback/details/541500/…
    • st3v3o
      st3v3o about 13 years
      good call..but I'm not sure I really full answered the question...but worth a shot :P
    • st3v3o
      st3v3o about 13 years
      oh I didn't realize you answered the question sorry Kev.
  • Kev
    Kev about 13 years
    +1 You'll probably win this, but I'll leave to run until the end of the bounty before awarding.
  • st3v3o
    st3v3o about 13 years
    FWIW I was doing some additional testing and just running Get-MailboxStatistics -Database <DB NAME> will output all of the users and system boxes that are listed. It will however skip over user accounts that have no statistical data to output (without displaying a warning)
  • st3v3o
    st3v3o about 13 years
    Looks like things are slightly different in the Exchange powershell way of doing things between 2007 and 2010 ...I tried your above setting and still get output with the EMS for 2010.
  • Kev
    Kev about 13 years
    @st3v3o - yep same here.