Is there a Powershell command that can be run to get a full list of exchange mailboxes and their retention policy

I am trying to create a powershell script on Exchange that can return the following info:

AD Account name
Mailbox name
Retention Policy value
Oldest item in mailbox
number of items in mailbox

Any help would be greatly appreciated.

TigerBloodAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AkhaterCommented:
The only thing can't get is the "Oldest item in mailbox"






$mbxs = get-mailbox -resultsize unlimited 
$all = @()

foreach ($mbx in $mbxs){
 
       $mbxstat = Get-MailboxStatistics $mbx

       $out = new-object psobject  
   
       $out | add-member noteproperty SamAccountName $mbx.SamAccountName
       $out | add-member noteproperty Alias	$mbx.alias
       $out | add-member noteproperty RetentionPolicy $mbx.RetentionPolicy
       $out | add-member noteproperty ItemCount $mbxstat.ItemCount
       $all += $out
} 



$all | export-csv c:\list.csv

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TigerBloodAuthor Commented:
Hi Akhater - the part of the script you posted works great.  But, there has to be a way to get the "oldest item in the mailbox".  Each email is date/ time stamped so I would be surprised if there was no command to get this info via powershell.  

If you know how to get the "oldest email in the mailbox" that would work for me.

We are trying to run this script so we can produce a report that tells us which mailbox has what retention policy assigned and the "oldest item (or email) in the mailbox" value when compared to the retention policy that is set should show us whether the retention policy is actually working properly, without us having to check each mailbox individually.

If you know of a more efficient way that how I am going about this that I would be very interested in seeing your solution :)

Thanks

0
e_aravindCommented:
I've tried to get the oldest item in the INBOX using the following
$olFolderInbox = 6
$outlook = new-object -com outlook.application;
$ns = $outlook.GetNameSpace("MAPI");
$inbox = $ns.GetDefaultFolder($olFolderInbox)
$ic=$inbox.items

foreach($x in $ic)
{
$arr+=@($x.receivedtime)
}

$arr1=$arr|sort
write-host "Oldest Item here is --> "$arr1[0]

Write-host "done"

Open in new window

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

TigerBloodAuthor Commented:
With the following command I can get the DisplayName, Folder Path, number of items in the folder, folder Size, oldestItemReceivedDate and NewestItemReceivedDate printing to the powerShell prompt.

foreach($mbx in Get-Mailbox){
Get-MailboxFolderStatistics -includeoldestandnewestitems $mbx.identity -FolderScope 'SentItems' | select @{n="DisplayName";e={$mbx.displayName}},FolderPath,ItemsInFolder,FolderSize,OldestItemreceivedDate,NewestItemreceivedDate
}

How can I get this to print to a CSV file?

Thanks
0
Suliman Abu KharroubIT Consultant Commented:
just append ">c:\file.csv" at the end.
0
TigerBloodAuthor Commented:
Was not able to export the oldest item in mailbox
0
markpalinuxCommented:


You post has helped me. I am adding this to see if it maybe of help to you...
When you start moving beyond simple mailbox stats some times you need access rights to the mailbox.

Maybe another way to report would be a client side outlook script ?

Mark
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.