Task – Get A List Of Mailboxes That Was Created In The Last One Week…

I had to get a list of mailboxes that was created in the last one week. Though it is quite easy, I thought that I will share it anyway. Get-Mailbox | Where-Object {$_.WhenCreated –ge ((Get-Date).Adddays(-7))} The above command will give you a list of all mailboxes that was created in the last one week, but…

I had to get a list of mailboxes that was created in the last one week. Though it is quite easy, I thought that I will share it anyway.

Get-Mailbox | Where-Object {$_.WhenCreated –ge ((Get-Date).Adddays(-7))}

The above command will give you a list of all mailboxes that was created in the last one week, but may not bring the properties that you are looking for. Modify the command with the values you need. For example,

Get-Mailbox | Where-Object {$_.WhenCreated –ge ((Get-Date).Adddays(-7))} | ft name, servername, database

You can export the result to a txt or csv file.

Get-Mailbox | Where-Object {$_.WhenCreated –ge ((Get-Date).Adddays(-7))} | ft name, servername, database | Out-File C:mailboxes.txt

Get-Mailbox | Where-Object {$_.WhenCreated –ge ((Get-Date).Adddays(-7))} | ft name, servername, database | Export-CSV c:mailboxes.csv

It is easy to extend the command to find a list of mailboxes that was created in the last one month. For the month of August, run

Get-Mailbox | Where-Object {($_.WhenCreated).Month –eq 8} | ft name, servername, database

Note that the value of month takes an integer.

Piping the above command to Meaure-Object will give you the number of mailboxes that was created.

Get-Mailbox | Where-Object {($_.WhenCreated).Month –eq 8} | Measure-Object

To get the list for the year 2009, run

Get-Mailbox | Where-Object {($_.WhenCreated).Year –eq 2009} | ft name, servername, database

13 Comments

  1. I want to get list of shared mailbox sorted by creation date. But record would be more than 5000. So can we implement some pagination kind of thing in power shell ? If yes how can I achieve that?

  2. Is it possible to do a direct filter instead of where-object since filter will return faster results?

  3. Include the parameter
    -resultsize unlimited
    to search more than the the default 1000 items

    Get-Mailbox -resultsize unlimited | Where-Object {$_.WhenMailboxCreated –ge ((Get-Date).Adddays(-7))} | ft name, servername, database

    1. Rajith Enchiparambil says:

      Thanks Mark.

  4. The attribute WhenCreated represents the date the AD account was created, not the date the mailbox was created (which might be days or months before the creation of the mailbox, depending on your situation).

    Use the attribute WhenMailboxCreated instead to filter the mailbox creation date.
    E.g:
    Get-Mailbox | Where-Object {$_.WhenMailboxCreated –ge ((Get-Date).Adddays(-7))} | ft name, servername, database

  5. thx for these great tipps!

    I would like to have a overview for 3month… (e.g. Januar Februar March)
    And if i export the file I need “;” between the entries.

    Any Ideas?

    Thx
    David

  6. Anonymous says:

    PowerShell does indeed rock, however that query is returning the date/time stamp when the user object was created not when the mailbox was created. If the mailbox always get's created right after the user account then that's good data. Unfortunately for me, I've got in some cases a few months before some user accounts get a mailbox.

    1. Try using $_.whenmailboxcreated instead of $_.whencreated

      1. Rajith Jose Enchiparambil says:

        Thanks Josh

  7. Rajith Jose Enchiparambil says:

    Thanks Paul.

  8. Paul Cunningham says:

    Great tip, thanks for that!

  9. Rajith Jose Enchiparambil says:

    Powershell is the future!

  10. Deepak Khandelwal says:

    It is amasing what Powershell can do for you.. Thanks for sharing

Leave a Reply

Your email address will not be published. Required fields are marked *