Get-Mailbox -ResultSize Unlimited | select DisplayName, Alias, Database, PrimarySmtpAddress,@{name=IssuewarningQuota;expression={if ($_.IssueWarningQuota -match "UNLIMITED") {"-1"} else {$_.IssueWarningQuota.value.tomb() }}},@{name=ProhibitSendQuota;expression={if ($_.ProhibitSendQuota -match "UNLIMITED") {"-1"} else {$_.ProhibitSendQuota.value.tomb() }}},@{name=ProhibitSendReceiveQuota;expression={if ($_.ProhibitSendReceiveQuota -match "UNLIMITED") {"-1"} else {$_.ProhibitSendReceiveQuota.value.tomb() }}},WhenCreated |export-csv C:\stats.csv
"DisplayName,Alias,MailboxSizeMB,ItemCount,PrimarysmtpAddress,IssueWarningQuotaMB,ProhibitSendQuotaMB,ProhibitSendReceiveQuotaMB,DatabaseName,CreationDate,LastLogonTime,LastLogoffTime,isActive" | out-file C:\MailstatsResult.csv
$csv = Import-csv -path "C:\stats.csv"
foreach($line in $csv)
{
$MailboxStats = Get-MailboxStatistics $Line.Alias | Select TotalItemSize,Itemcount,LastLogoffTime,LastLogonTime
$L = "{0:N0}" -f $mailboxstats.totalitemsize.value.toMB()
$Size = ""
$Len = $L.Split(',')
for ($i=0; $i -lt $Len.length; $i++)
{
$Size = $Size +$Len[$i]
}
$temp=$Line.PrimarysmtpAddress
$adobjroot = [adsi]''
$objdisabsearcher = New-Object System.DirectoryServices.DirectorySearcher($adobjroot)
$objdisabsearcher.filter = "(&(objectCategory=Person)(objectClass=user)(mail= $Temp)(userAccountControl:1.2.840.113556.1.4.803:=2))"
$resultdisabaccn = $objdisabsearcher.findone() | select path
if($resultdisabaccn.path)
{
$actStatus = "1"
}
Else
{
$actStatus = "0"
}
$out =$Line.Displayname + "," + $Line.Alias + "," + $Size + "," + $MailboxStats.ItemCount + "," + $Line.PrimarySmtpAddress + "," + $Line.IssueWarningQuota + "," + $Line.ProhibitSendQuota + "," + $Line.ProhibitSendReceiveQuota + "," + $Line.Database + "," + $Line.WhenCreated + "," + $MailboxStats.LastLogonTime + "," + $MailboxStats.LastLogoffTime + "," + $actStatus
$Out | Out-File C:\MailstatsResult.csv -Append
}
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)