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 ArchiveTotalDeleteditemSiz
e & ArchiveTotalDeleteditemCou
nt (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.cs
v"
# ==========================
==========
==========
===
# ========== 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(
$MailOlder
ThanDays))
.ToShortDa
teString()
# 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-MailboxFolderStatistic
s -Folderscope All -IncludeOldestAndNewestIte
ms
# 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.OldestItemReceived
Date
}
# 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.
ByteQuanti
fiedSize]$
MBXSearch.
ResultItem
sSize).ToB
ytes()
# 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.
ByteQuanti
fiedSize]$
MBXStats.T
otalItemSi
ze).ToByte
s()
# 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.ResultItemsCoun
t
$Hash.ArchiveItemsSizeByte
s = "{0:n0}" -f $ArchiveItemSizeBytes
$Hash.ArchiveItemsSizeMBs = "{0:n4}" -f ($ArchiveItemSizeBytes / 1MB)
$Hash.DeletedItemCount = $MBXStats.DeletedItemCount
$Hash.TotalDeletedItemSize
= $MBXStats.TotalDeletedItem
Size
$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.
ByteQuanti
fiedSize]$
MBXStats.T
otalItemSi
ze).ToByte
s()
# 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.TotalDeletedItem
Size
$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,Ite
msCount,It
emsSizeByt
es,ItemsSi
zeMBs,Arch
iveItemsCo
unt,Archiv
eItemsSize
Bytes,Arch
iveItemsSi
zeMBs,Tota
lDeletedIt
emSize,Del
etedItemCo
unt | 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
Did you sort out?
I suggest you hire a consultant to do this job for you.
Thanks
MAS