I have created a script which the purpose is to grab everyone's mailbox in the environment and list their name, mailbox size, item count, last person to log on, last log on time and when it was created. I'm going to use this to review mailboxes that have been in our environment for a while but have very little content.
The below script works. I'm using "smith" as a test so that it pulls everyone who has smith in their display name.
The problem I have is it out puts the data with the table headers every single time. I'd like it if possible to just list the headers once and then output everyone's data below that.
Secondly I need to pipe it out to a file (csv) so I can work with the data. I've tried >, out-file and add-content but it either exports just one persons data or giberish.
foreach ($person in $mailbox){
$whencreated = $person.whencreated
Get-mailboxstatistics -Identity "$person" | ft displayname, totalitemsize, itemcount,lastloggedonuseraccount, lastlogontime, @{Label="WhenCreated";Expression={$whencreated} }
}