2014-12-22 16:59:23 +02:00
|
|
|
|
#[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
|
|
|
|
#write-output "" # workaround to prevent the byte order mark to be at the beginning of the first section
|
|
|
|
|
#####################################################################################
|
|
|
|
|
# Exchange 2010 : per user mailbox size
|
|
|
|
|
# Author: Marius Pana
|
2014-12-23 17:58:40 +02:00
|
|
|
|
# Company: Spearhead Systems
|
2014-12-22 16:59:23 +02:00
|
|
|
|
# Date 12/16/14
|
|
|
|
|
#####################################################################################
|
|
|
|
|
|
|
|
|
|
add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
|
|
|
|
|
|
|
|
|
|
# measure time
|
|
|
|
|
#Measure-Command {$(Foreach ($mailbox in Get-Recipient -ResultSize Unlimited -RecipientType UserMailbox){
|
|
|
|
|
#$Stat = $mailbox | Get-MailboxStatistics | Select TotalItemSize
|
|
|
|
|
# New-Object PSObject -Property @{
|
|
|
|
|
# PrimarySmtpAddress = $mailbox.PrimarySmtpAddress
|
|
|
|
|
# TotalItemSize = $Stat.TotalItemSize.value.ToMB()
|
|
|
|
|
# }
|
2014-12-23 17:58:40 +02:00
|
|
|
|
#}) | Select PrimarySmtpAddress,TotalItemSize |
|
2014-12-22 16:59:23 +02:00
|
|
|
|
#Export-CSV C:\CMK-MailboxReport.csv -NTI}
|
|
|
|
|
|
|
|
|
|
# filename for timestamp
|
|
|
|
|
$remote_host = $env:REMOTE_HOST
|
|
|
|
|
$agent_dir = $env:MK_CONFDIR
|
|
|
|
|
|
|
|
|
|
$timestamp = $agent_dir + "\timestamp."+ $remote_host
|
|
|
|
|
|
|
|
|
|
# execute agent only every $delay seconds - 24 hours
|
|
|
|
|
$delay = 86400
|
|
|
|
|
|
|
|
|
|
# does $timestamp exist?
|
|
|
|
|
If (Test-Path $timestamp){
|
|
|
|
|
# cat existing outut
|
|
|
|
|
write-host "<<<exchange_user_mbx_size>>>"
|
|
|
|
|
Get-Content C:\CMK-MailboxReport.csv
|
|
|
|
|
$filedate = (ls $timestamp).LastWriteTime
|
|
|
|
|
$now = Get-Date
|
|
|
|
|
$earlier = $now.AddSeconds(-$delay)
|
2014-12-23 17:58:40 +02:00
|
|
|
|
# exit if timestamp too young
|
2014-12-22 16:59:23 +02:00
|
|
|
|
if ( $filedate -gt $earlier ) { exit }
|
|
|
|
|
}
|
|
|
|
|
# create new timestamp file
|
|
|
|
|
New-Item $timestamp -type file -force | Out-Null
|
|
|
|
|
|
|
|
|
|
# calculate unix timestamp
|
|
|
|
|
$epoch=[int][double]::Parse($(Get-Date -date (Get-Date).ToUniversalTime()-uformat %s))
|
|
|
|
|
|
|
|
|
|
$(Foreach ($mailbox in Get-Recipient -ResultSize Unlimited -RecipientType UserMailbox){
|
|
|
|
|
$Stat = $mailbox | Get-MailboxStatistics | Select TotalItemSize
|
|
|
|
|
New-Object PSObject -Property @{
|
|
|
|
|
PrimarySmtpAddress = $mailbox.PrimarySmtpAddress
|
|
|
|
|
TotalItemSize = $Stat.TotalItemSize.value.ToMB()
|
|
|
|
|
}
|
2014-12-23 17:58:40 +02:00
|
|
|
|
}) | Select PrimarySmtpAddress,TotalItemSize |
|
2014-12-22 16:59:23 +02:00
|
|
|
|
Export-CSV C:\CMK-MailboxReport.csv -NoTypeInformation
|
|
|
|
|
|
|
|
|
|
(Get-Content C:\CMK-MailboxReport.csv) | Foreach-Object {$_ -replace '"', ''} | Foreach-Object {$_ -replace ',', ' '} | select -Skip 1 | Set-Content C:\CMK-MailboxReport.csv
|