Script for mailbox size and last logon date for exchange online to Excel

connect-exchangeonline

$Excel = New-Object -ComObject Excel.Application
$Excel.Visible = $True
$Excel = $Excel.Workbooks.Add()
$Sheet = $Excel.Worksheets.Item(1)
$Sheet.Name = “Mailbox Stats”

$Sheet.Cells.Item(1,1) = “Name”
$Sheet.Cells.Item(1,2) = “Last Log On”
$Sheet.Cells.Item(1,3) = “MailBox Size”

$intRow = 2

$box = get-exomailbox | select userprincipalname

foreach ($i in $box.userprincipalname){

$stats = Get-EXOMailboxStatistics -Identity $i -Properties lastlogontime | select displayname, lastlogontime, @{label=”TotalItemSize”;expression={[math]::Round(`
($_.TotalItemSize.ToString().Split("(")[1].Split(" ")[0].Replace(",","")/1MB),2)}}

$Sheet.Cells.Item($intRow, 1) = $stats.displayname
$Sheet.Cells.Item($intRow, 2) = $stats.lastlogontime
$Sheet.Cells.Item($intRow, 3) = $stats.TotalItemSize
$intRow ++

}

Dennis, welcome to Powershell.org. Please take a moment and read the very first post on top of the list of this forum: Read Me Before Posting! You’ll be Glad You Did!.

When you post code or error messages or sample data or console output format it as code using the code tags “PRE”, please. You can edit your existing post. You don’t have to create a new one. Thanks in advance.

And BTW: - you should ask a clear question.