Powershell script to check the TotalDeletedItemSize

CiscoAzn
CiscoAzn used Ask the Experts™
on
When running the command "Get-MailboxStatistics <username> | FL" there is an output for "TotalDeletedItemSize". Is there a way to have a schedule script to run that would show all users in an OU that has over 90GB for the TotalDeletedItemSize? Just need a weekly report of this.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Jose Gabriel Ortega CastroTop Rated Freelancer on MS Technologies
Awarded 2018
Distinguished Expert 2018

Commented:
This will be my code

Add-pssnapin Microsoft.Exchange.Management.PowerShell.E2010
$ReportNameAndPath="$env:userprofile\desktop\report.html"
$css3="<style>td,th{border:1px solid #ddd;padding:8px}th{padding-bottom:12px;text-align:left;background-color:#4caf50;color:#fff}</style>"
$OUName = "Accounting"
$OUData = Get-OrganizationalUnit $OUName
Get-mailbox -OrganizationalUnit $($OUData.DistinguishedName) -resultsize unlimited | Get-MailboxStatistics | select Displayname,ItemCount,TotalDeletedItemsize | sort-object TotalDeletedItemSize -Descending | ConvertTo-Html -Head $css3 | Out-File $ReportNameAndPath

Open in new window


Output
PS Output

Author

Commented:
Thanks Jose but these mailboxes are on O365. What's the code to call it in the beginning? Under the $OUName would that be the DN of the OU?
Jose Gabriel Ortega CastroTop Rated Freelancer on MS Technologies
Awarded 2018
Distinguished Expert 2018

Commented:
Clarify in your question that is for Office 365, that's not specified anywhere :P
TotalDeletedSize on 90Gb ? why?
That would be an almost 100Gb mailbox that has 90Gb deleted, it's a hard condition to hit.
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

Top Rated Freelancer on MS Technologies
Awarded 2018
Distinguished Expert 2018
Commented:
On O365
Script1 Create the password as SecureString (COnvert password to secure string and save it into "C:\encrypted.txt"
Password can be set and plain text to get encrypted or use an app password in case of MFA enabled.
"P@ssword1" | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString | Out-File "C:\encrypted.txt"

Open in new window


Script2 Connect to o365
$User="test@truefact.onmicrosoft.com"
$KeyFile = "C:\encrypted.txt"
$UserCredential = New-Object -TypeName System.Management.Automation.PSCredential  -ArgumentList $User, (Get-Content $keyFile | ConvertTo-SecureString)
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session -DisableNameChecking

$ReportNameAndPath="$env:userprofile\desktop\report.html"
$css3="<style>td,th{border:1px solid #ddd;padding:8px}th{padding-bottom:12px;text-align:left;background-color:#4caf50;color:#fff}</style>"

Get-mailbox -resultsize unlimited | Get-MailboxStatistics | select Displayname,ItemCount,TotalDeletedItemsize | sort-object TotalDeletedItemSize -Descending | ConvertTo-Html -Head $css3 | Out-File $ReportNameAndPath

Open in new window


Either way microsoft will request to use the
$UserCredential= get-credential

Open in new window


Here I'm creating the Password from the txt file on script2.

Author

Commented:
Thanks Jose!
Jose Gabriel Ortega CastroTop Rated Freelancer on MS Technologies
Awarded 2018
Distinguished Expert 2018

Commented:
Np! :)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial