With Single Item Recovery in Exchange 2010 and Exchange 2013, the Recoverable Items Folder in an Exchange Mailbox becomes one of the things you may want to pay some more special attention to in the course of managing the disk resource that are being consumed within your Exchange Org. The following is a script that does another take on ItemAge reporting by basically crawling every item in a folder and then grouping the DateTimeRecieved (to get the age of the Item) and the ModifiedTime(which is when its deleted). The script produces a report like the following for the Mailbox you run it against
To use the script you just need to enter the SMTPAddress of the Mailbox you want to run it against and as long as you have rights to the mailbox you should get a report.
I've put a download of the script here the code looks like
To use the script you just need to enter the SMTPAddress of the Mailbox you want to run it against and as long as you have rights to the mailbox you should get a report.
I've put a download of the script here the code looks like
- ## Get the Mailbox to Access from the 1st commandline argument
- $MailboxName = $args[0]
- ## Load Managed API dll
- Add-Type -Path "C:\Program Files\Microsoft\Exchange\Web Services\2.0\Microsoft.Exchange.WebServices.dll"
- ## Set Exchange Version
- $ExchangeVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP2
- ## Create Exchange Service Object
- $service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService($ExchangeVersion)
- ## Set Credentials to use two options are availible Option1 to use explict credentials or Option 2 use the Default (logged On) credentials
- #Credentials Option 1 using UPN for the windows Account
- $psCred = Get-Credential
- $creds = New-Object System.Net.NetworkCredential($psCred.UserName.ToString(),$psCred.GetNetworkCredential().password.ToString())
- $service.Credentials = $creds
- #Credentials Option 2
- #service.UseDefaultCredentials = $true
- ## Choose to ignore any SSL Warning issues caused by Self Signed Certificates
- ## Code From http://poshcode.org/624
- ## Create a compilation environment
- $Provider=New-Object Microsoft.CSharp.CSharpCodeProvider
- $Compiler=$Provider.CreateCompiler()
- $Params=New-Object System.CodeDom.Compiler.CompilerParameters
- $Params.GenerateExecutable=$False
- $Params.GenerateInMemory=$True
- $Params.IncludeDebugInformation=$False
- $Params.ReferencedAssemblies.Add("System.DLL") | Out-Null
- $TASource=@'
- namespace Local.ToolkitExtensions.Net.CertificatePolicy{
- public class TrustAll : System.Net.ICertificatePolicy {
- public TrustAll() {
- }
- public bool CheckValidationResult(System.Net.ServicePoint sp,
- System.Security.Cryptography.X509Certificates.X509Certificate cert,
- System.Net.WebRequest req, int problem) {
- return true;
- }
- }
- }
- '@
- $TAResults=$Provider.CompileAssemblyFromSource($Params,$TASource)
- $TAAssembly=$TAResults.CompiledAssembly
- ## We now create an instance of the TrustAll and attach it to the ServicePointManager
- $TrustAll=$TAAssembly.CreateInstance("Local.ToolkitExtensions.Net.CertificatePolicy.TrustAll")
- [System.Net.ServicePointManager]::CertificatePolicy=$TrustAll
- ## end code from http://poshcode.org/624
- ## Set the URL of the CAS (Client Access Server) to use two options are availbe to use Autodiscover to find the CAS URL or Hardcode the CAS to use
- #CAS URL Option 1 Autodiscover
- $service.AutodiscoverUrl($MailboxName,{$true})
- "Using CAS Server : " + $Service.url
- #CAS URL Option 2 Hardcoded
- #$uri=[system.URI] "https://casservername/ews/exchange.asmx"
- #$service.Url = $uri
- ## Optional section for Exchange Impersonation
- #$service.ImpersonatedUserId = new-object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress, $MailboxName)
- $PR_MESSAGE_SIZE_EXTENDED = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(3592,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Long);
- $psPropset = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)
- $psPropset.Add($PR_MESSAGE_SIZE_EXTENDED)
- # Bind to the MsgFolderRoot folder
- $folderid= new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::RecoverableItemsDeletions,$MailboxName)
- $RecoverableItemsDeletions = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid,$psPropset)
- $rptObject = "" | Select MailboxName,TotalNumberOfItems,TotalSize,AgeLessThan7days,AgeLessThan7daysSize,Age7To30Days,Age7To30DaysSize,Age1to6Months,Age1to6MonthsSize,Age6To12Months,Age6To12MonthsSize,AgeGreator12Months,AgeGreator12MonthsSize,DeletedLessThan7days,DeletedLessThan7daysSize,Deleted7To30Days,Deleted7To30DaysSize,Deleted1to6Months,Deleted1to6MonthsSize,Deleted6To12Months,Deleted6To12MonthsSize,DeletedGreator12Months,DeletedGreator12MonthsSize
- $rptObject.AgeLessThan7daysSize = [INT64]0
- $rptObject.Age7To30DaysSize = [INT64]0
- $rptObject.Age1to6MonthsSize = [INT64]0
- $rptObject.Age6To12MonthsSize = [INT64]0
- $rptObject.AgeGreator12MonthsSize = [INT64]0
- $rptObject.AgeLessThan7days = [INT64]0
- $rptObject.Age7To30Days = [INT64]0
- $rptObject.Age1to6Months = [INT64]0
- $rptObject.Age6To12Months = [INT64]0
- $rptObject.AgeGreator12Months = [INT64]0
- $rptObject.DeletedLessThan7daysSize = [INT64]0
- $rptObject.Deleted7To30DaysSize = [INT64]0
- $rptObject.Deleted1to6MonthsSize = [INT64]0
- $rptObject.Deleted6To12MonthsSize = [INT64]0
- $rptObject.DeletedGreator12MonthsSize = [INT64]0
- $rptObject.DeletedLessThan7days = [INT64]0
- $rptObject.Deleted7To30Days = [INT64]0
- $rptObject.Deleted1to6Months = [INT64]0
- $rptObject.Deleted6To12Months = [INT64]0
- $rptObject.DeletedGreator12Months = [INT64]0
- $rptObject.MailboxName = $MailboxName
- $rptObject.TotalNumberOfItems = $RecoverableItemsDeletions.TotalCount
- $folderSizeVal = $null;
- if($RecoverableItemsDeletions.TryGetProperty($PR_MESSAGE_SIZE_EXTENDED,[ref]$folderSizeVal)){
- $rptObject.TotalSize = [Math]::Round([Int64]$folderSizeVal / 1mb,2)
- }
- #Define ItemView to retrive just 1000 Items
- $ivItemView = New-Object Microsoft.Exchange.WebServices.Data.ItemView(1000)
- $itemPropset= new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::IdOnly)
- $itemPropset.Add([Microsoft.Exchange.WebServices.Data.ItemSchema]::DateTimeReceived)
- $itemPropset.Add([Microsoft.Exchange.WebServices.Data.ItemSchema]::DateTimeCreated)
- $itemPropset.Add([Microsoft.Exchange.WebServices.Data.ItemSchema]::LastModifiedTime)
- $itemPropset.Add([Microsoft.Exchange.WebServices.Data.ItemSchema]::Size)
- $fiItems = $null
- $itemCnt = 0
- do{
- $fiItems = $service.FindItems($RecoverableItemsDeletions.Id,$ivItemView)
- #[Void]$service.LoadPropertiesForItems($fiItems,$psPropset)
- foreach($Item in $fiItems.Items){
- $Notadded = $true
- $dateVal = $null
- if($Item.TryGetProperty([Microsoft.Exchange.WebServices.Data.ItemSchema]::DateTimeReceived,[ref]$dateVal )-eq $false){
- $dateVal = $Item.DateTimeCreated
- }
- $modDateVal = $null
- if($Item.TryGetProperty([Microsoft.Exchange.WebServices.Data.ItemSchema]::LastModifiedTime,[ref]$modDateVal)){
- if($modDateVal -gt (Get-Date).AddDays(-7))
- {
- $rptObject.DeletedLessThan7days++
- $rptObject.DeletedLessThan7daysSize += $Item.Size
- $Notadded = $false
- }
- if($modDateVal -le (Get-Date).AddDays(-7) -band $modDateVal -gt (Get-Date).AddDays(-30))
- {
- $rptObject.Deleted7To30Days++
- $rptObject.Deleted7To30DaysSize += $Item.Size
- $Notadded = $false
- }
- if($modDateVal -le (Get-Date).AddDays(-30) -band $modDateVal -gt (Get-Date).AddMonths(-6))
- {
- $rptObject.Deleted1to6Months++
- $rptObject.Deleted1to6MonthsSize += $Item.Size
- $Notadded = $false
- }
- if($modDateVal -le (Get-Date).AddMonths(-6) -band $modDateVal -gt (Get-Date).AddMonths(-12))
- {
- $rptObject.Deleted6To12Months++
- $rptObject.Deleted6To12MonthsSize += $Item.Size
- $Notadded = $false
- }
- if($modDateVal -le (Get-Date).AddYears(-1))
- {
- $rptObject.DeletedGreator12Months++
- $rptObject.DeletedGreator12MonthsSize += $Item.Size
- $Notadded = $false
- }
- }
- if($dateVal -gt (Get-Date).AddDays(-7))
- {
- $rptObject.AgeLessThan7days++
- $rptObject.AgeLessThan7daysSize += $Item.Size
- $Notadded = $false
- }
- if($dateVal -le (Get-Date).AddDays(-7) -band $dateVal -gt (Get-Date).AddDays(-30))
- {
- $rptObject.Age7To30Days++
- $rptObject.Age7To30DaysSize += $Item.Size
- $Notadded = $false
- }
- if($dateVal -le (Get-Date).AddDays(-30) -band $dateVal -gt (Get-Date).AddMonths(-6))
- {
- $rptObject.Age1to6Months++
- $rptObject.Age1to6MonthsSize += $Item.Size
- $Notadded = $false
- }
- if($dateVal -le (Get-Date).AddMonths(-6) -band $dateVal -gt (Get-Date).AddMonths(-12))
- {
- $rptObject.Age6To12Months++
- $rptObject.Age6To12MonthsSize += $Item.Size
- $Notadded = $false
- }
- if($dateVal -le (Get-Date).AddYears(-1))
- {
- $rptObject.AgeGreator12Months++
- $rptObject.AgeGreator12MonthsSize += $Item.Size
- $Notadded = $false
- }
- }
- $ivItemView.Offset += $fiItems.Items.Count
- }while($fiItems.MoreAvailable -eq $true)
- if($rptObject.AgeLessThan7daysSize -gt 0){
- $rptObject.AgeLessThan7daysSize = [Math]::Round($rptObject.AgeLessThan7daysSize/ 1mb,2)
- }
- if($rptObject.Age7To30DaysSize -gt 0){
- $rptObject.Age7To30DaysSize = [Math]::Round($rptObject.Age7To30DaysSize/ 1mb,2)
- }
- if($rptObject.Age1to6MonthsSize -gt 0){
- $rptObject.Age1to6MonthsSize = [Math]::Round($rptObject.Age1to6MonthsSize/ 1mb,2)
- }
- if($rptObject.Age6To12MonthsSize -gt 0){
- $rptObject.Age6To12MonthsSize = [Math]::Round($rptObject.Age6To12MonthsSize/ 1mb,2)
- }
- if($rptObject.AgeGreator12MonthsSize -gt 0){
- $rptObject.AgeGreator12MonthsSize = [Math]::Round($rptObject.AgeGreator12MonthsSize/ 1mb,2)
- }
- if($rptObject.DeletedLessThan7daysSize -gt 0){
- $rptObject.DeletedLessThan7daysSize = [Math]::Round($rptObject.DeletedLessThan7daysSize/ 1mb,2)
- }
- if($rptObject.Deleted7To30DaysSize -gt 0){
- $rptObject.Deleted7To30DaysSize = [Math]::Round($rptObject.Deleted7To30DaysSize/ 1mb,2)
- }
- if($rptObject.Deleted1to6MonthsSize -gt 0){
- $rptObject.Deleted1to6MonthsSize = [Math]::Round($rptObject.Deleted1to6MonthsSize/ 1mb,2)
- }
- if($rptObject.Deleted6To12MonthsSize -gt 0){
- $rptObject.Deleted6To12MonthsSize = [Math]::Round($rptObject.Deleted6To12MonthsSize/ 1mb,2)
- }
- if($rptObject.DeletedGreator12MonthsSize -gt 0){
- $rptObject.DeletedGreator12MonthsSize = [Math]::Round($rptObject.DeletedGreator12MonthsSize/ 1mb,2)
- }
- $a = "<style>"
- $a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
- $a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;}"
- $a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;}"
- $a = $a + "</style>"
- $rptObject | ConvertTo-Html -As LIST -Head $a | Out-File c:\temp\RetainedItemReport.htm