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
Please let me know if you have any questions in the comments section.
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?
Is it possible to do a direct filter instead of where-object since filter will return faster results?
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
Thanks Mark.
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
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
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.
Try using $_.whenmailboxcreated instead of $_.whencreated
Thanks Josh
Thanks Paul.
Great tip, thanks for that!
Powershell is the future!
It is amasing what Powershell can do for you.. Thanks for sharing