Wednesday, 30 September 2009

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


5 comments:

Unknown said...

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

Rajith Jose Enchiparambil said...

Powershell is the future!

Paul Cunningham said...

Great tip, thanks for that!

Rajith Jose Enchiparambil said...

Thanks Paul.

Anonymous said...

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.

Post a Comment