Exchange 2010 - Archiveable TotalDeletedItemSize

Thanks to Rick_2CA - https://gallery.technet.microsoft.com/office/Mailbox-Pre-Archive-347f9162/view/Discussions

I have been able to Modify this script to include: TotalDeleteditemSize and TotalDeleteditemCount

This outputs the below and works exactly how I want:

ItemsCount      
ArchiveItemsCount      
ItemsSizeBytes      
ArchiveItemsSizeBytes      
TotalDeletedItemSize            
DeletedItemCount


The part I am having trouble with, and where I would like a push in the right direction is how to obtain the ArchiveTotalDeleteditemSize & ArchiveTotalDeleteditemCount (The count and size of data that CAN be archived, same as what is output from "ArchiveItemsSizeBytes")

Below is the script, that I have manipulated to include the

TotalDeleteditemSize & TotalDeleteditemCount......

I have attempted to match what was already in the script, by copying the code, and changing the values (Via Powershell ISE), However, I just end up with nothing being returned or getting the identical results as the ArchiveItemsizebytes

Essentially I am after the Archivable size & Count for recoverable deleted items

Any assistance would be greatly appreciated!!!

If I have worded anything wrongly, or something does not make sense, please let me know, and I will be happy to clarify...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


# Exchange 2010 Mailbox PreArchive Statistics
# Purpose:  Query mailboxes for mail older than X days in order to plan archive database storage requirements.

## Organizational Management & Discovery Management security group rights are required to execute this script.
## (Note:  I haven't gone terribly far to see what the minimum security rights are.)
## Execution of the script from the Exchange Management Shell (EMS) will provide feedback on execution.

# =================================================
# ==========  CHOOSE CUSTOM SETTINGS  =============

# =================================================

# Set the Mailbox variable to the query you wish to search
# Enable ONE of the following $Mailbox options.  They are ordered in such a way that if two
# options are enabled the last one set will be a smaller set of users than the previous.
## Search a single database (EDIT THE DATABASE NAME)
    $Mailbox = Get-MailboxDatabase -Identity <DATABASE NAME> | Get-Mailbox -
    ResultSize Unlimited
# Set the minimum mail age that should be collected.  Note:  Leap years are not automatically calculated.

    $MailOlderThanDays = 182

# Set your folder path.  Using '$env:userprofile + "\" + "Desktop" + "\"' puts the report on the desktop
# of the user that executes the script.
    $filepath = $env:userprofile + "\" + "Desktop" + "\"
# Name your output file
    $filename = "ArchiveStatisticsPlanner_Results.csv"

# =================================================
# ==========  End CUSTOM SETTINGS  ================
# =================================================

# Capture the script start time.  Used at the end of the script.
    $StartTime = Get-Date -DisplayHint Time

# If both variables were setup in the text file input option we confirm the file exists.
    If (($TXTPath) -and ($TXTName)) {
    $TXT = $TXTPath + $TXTName
# If the file exists set $Mailbox to grab the content.  If not end script.
    If (test-path $TXT){
    $Mailbox = Get-Content $TXT
    }
    else {
    Write-Host "The file " $TXT " does not exist." -foreground red
    Break
    }
    }

# Confirm $Mailbox was set properly and throw an error if not.
    If (!$Mailbox) {
    Write-Host "The search option has not been properly configured or the text file is blank.  Please edit the search options and try again." -foreground red
    Break
    }

# Declare the array to be used to capture and store the query returns for exporting
    $Arr = @()


# Compute the date to be used for minimum mail age.  
    $QueryDate =
    [DateTime]::Now.Subtract([TimeSpan]::FromDays($MailOlderThanDays)).ToShortDateString()
# Cycle through each mailbox to begin your collection
    Foreach ($MBX in $Mailbox) {
# Set the hash and a variable fresh for each ForEach
    $Hash = @{}
    $MBXDatabase = $Null


# Depending on your initial query choice we may or may not easily access the mailbox's database.
# First we attempt to set the value.  If the value turns out null we query for the information
    $MBXDatabase = $MBX.Database

    If (!$MBXDatabase){
    $MBX = Get-Mailbox -Identity $MBX
# Check to see if the value of $MBX results in multiple matches.  If it does log and move to the next item.
    If ($MBX.GetType().IsArray) {
    $DuplicatesError = "The search for this user resulted in multiple matches.  Please run again with a unique value."
    $Hash = @{}
    $Hash.User = $MBX
    $Hash.Database = $DuplicatesError
    $Arr += New-Object PSObject -Property $Hash
    Continue
    }
    $MBXDatabase = $MBX.Database
    }

# Grab the folder statistics of the mailbox for the purpose of filtering out mailboxes with no data older than what you want.
    $FolderStatistics = Get-Mailbox -Identity $MBX | Get-MailboxFolderStatistics -Folderscope All -IncludeOldestAndNewestItems

# Sort through the OldestItemReceiveDates for each folder and pick out only the oldest date.
    $Oldest = $FolderStatistics | Where-Object {$_.OldestItemReceivedDate} |  Sort-Object OldestItemReceivedDate | Select-Object OldestItemReceivedDate -First 1

# Find out how old the oldest item is from today
    If ($Oldest){
    $OldestDays = New-TimeSpan -Start $Oldest.OldestItemReceivedDate
    }
# Convert the oldest item age to simple days
    $OldestDays = $OldestDays.Days

# If the oldest item age is greater than or equal to the minimum age set we'll query the mailbox
    If ($OldestDays -ge $MailOlderThanDays) {
# Search the mailbox for items sent on or before the query date.  EstimateResultOnly insures we just collect stats.
    $MBXSearch = Search-Mailbox -Identity $MBX -SearchQuery "sent:<=$QueryDate" -EstimateResultOnly -SearchDumpster:$True -DoNotIncludeArchive
# Convert the size field to a more useable value
    $ArchiveItemSizeBytes = ([Microsoft.Exchange.Data.ByteQuantifiedSize]$MBXSearch.ResultItemsSize).ToBytes()

# Query for today's mailbox size and item count for reference
    $MBXStats = Get-MailboxStatistics -Identity $MBX
# Convert the size field to a more useable value
    $ItemSizeBytes = ([Microsoft.Exchange.Data.ByteQuantifiedSize]$MBXStats.TotalItemSize).ToBytes()

# Save our collection to a hash table and write the entry to an array
    $Hash = @{}
    $Hash.User = $MBX
    $Hash.Database = $MBXDatabase
    $Hash.Identity = $MBX.Identity
    $Hash.ItemsCount = $MBXStats.ItemCount
    $Hash.ItemsSizeBytes = "{0:n0}" -f $ItemSizeBytes
    $Hash.ItemsSizeMBs = "{0:n4}" -f ($ItemSizeBytes / 1MB)
    $Hash.ArchiveItemsCount = $MBXSearch.ResultItemsCount
    $Hash.ArchiveItemsSizeBytes = "{0:n0}" -f $ArchiveItemSizeBytes
    $Hash.ArchiveItemsSizeMBs = "{0:n4}" -f ($ArchiveItemSizeBytes / 1MB)
    $Hash.DeletedItemCount = $MBXStats.DeletedItemCount
    $Hash.TotalDeletedItemSize = $MBXStats.TotalDeletedItemSize

    $Arr += new-object psobject -property $Hash
    }
# If the mailbox has no archive data we pull the to date data for reference
    Else {
# Query for today's mailbox size and item count for reference
    $MBXStats = Get-MailboxStatistics -Identity $MBX
# Convert the size field to a more useable value
    $ItemSizeBytes = ([Microsoft.Exchange.Data.ByteQuantifiedSize]$MBXStats.TotalItemSize).ToBytes()

# Save our collection to a hash table and write the entry to an array
    $Hash = @{}
    $Hash.User = $MBX
    $Hash.Database = $MBXDatabase
    $Hash.Identity = $MBX.Identity
    $Hash.ItemsCount = $MBXStats.ItemCount
    $Hash.ItemsSizeBytes = "{0:n0}" -f $ItemSizeBytes
    $Hash.ItemsSizeMBs = "{0:n4}" -f ($ItemSizeBytes / 1MB)
    $Hash.DeletedItemCount = $MBXStats.DeletedItemCount
    $Hash.TotalDeletedItemSize = $MBXStats.TotalDeletedItemSize

    $Arr += new-object psobject -property $Hash
    }
    }

# Set the path and filename of your output file
    $CSV = $Filepath + $Filename
# Order your array, sort your array, and export your array to a CSV file
    $Arr
    $Arr | Select-Object User,Database,Identity,ItemsCount,ItemsSizeBytes,ItemsSizeMBs,ArchiveItemsCount,ArchiveItemsSizeBytes,ArchiveItemsSizeMBs,TotalDeletedItemSize,DeletedItemCount | Sort-Object User | Export-CSV $CSV -NoTypeInformation

# Display the start and end time of the script.
    $EndTime = Get-Date -DisplayHint Time
    Write-Host "The script has completed and your CSV file has been saved as" $CSV".  Data has been collected on items that are" $MailOlderThanDays "days or older.  This resulted in a collection of items sent on or before" $QueryDate"." -foreground yellow
# Show the start/stop times of the script.  Used to set expectations on future run times.
    Write-Host "Script Start time:  " $StartTime -foreground cyan
    Write-Host "Script End time:  " $EndTime -foreground cyan
Antonio MartinielloJnr Exchange AdministratorAsked:
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.

MAS (MVE)EE Solution Guide - Technical Dept HeadCommented:
Hi Antonio,
Did you sort out?
I suggest you hire a consultant to do this job for you.

Thanks
MAS
0
Antonio MartinielloJnr Exchange AdministratorAuthor Commented:
Closing
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
Antonio MartinielloJnr Exchange AdministratorAuthor Commented:
No help received..
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.