Exchange - listing mailboxes in an OU with their mailbox size Exchange - listing mailboxes in an OU with their mailbox size powershell powershell

Exchange - listing mailboxes in an OU with their mailbox size


Why the dsquery?

get-mailbox -OrganizationalUnit "ou=Departed,ou=Staff,dc=COMPANY,dc=local" -resultsize unlimited | get-mailboxstatistics | ft DisplayName,TotalItemSize,Itemcount


I've got something for you, even though it's a little late.You just need to adjust every Searchbase with OU and DC, the Email-Adresses at the end and the SMTP-Server, then you get an Email with a CSV-Attachment that contains every OU with Counts of active and inactive Mailboxes and a list with every mailbox and its parameters.You can also trigger it with the Task-Scheduler of Windows, so it's an automatic report.

Add-PSSnapin Microsoft.Exchange.Management.Powershell.SnapIn;$Kunden=Get-ADOrganizationalUnit -Filter * -SearchBase "OU=Kunden,DC=domain,DC=domain"$leerzeile ="`n"#Funktion für 10 GB Kontrollefunction getUber10 ($name){$Uberschreit=0$anzahluber10=0$anzahl=0$UserList = Get-Mailbox -OrganizationalUnit "$name" |Get-MailboxStatistics$großen = $UserList |Select TotalItemSizefor($y=0; $y -lt $großen.Length; $y++){if($großen[$y].totalItemSize.value.toMB() -gt 10000){$wieoft=$großen[$y].totalItemSize.value.toMB() * 0.0001$anzahluber10 = $anzahluber10 +  [Math]::Ceiling($wieoft) - 1}}$anzahluber10}#Liste aller Kunden mit PostfachanzahlGet-ADOrganizationalUnit -Filter * -SearchBase "OU=Kunden, DC=domain, DC=domain" |Select-Object Name, @{n="Postfach-Anzahl";e = {(Get-ADUser -Filter {(EmailAddress -like "*@*") -and (Enabled -eq "True")} -SearchBase $_).count}},`@{n="Deaktivierte Postfächer";e = {(Get-ADUser -Filter {Enabled -eq "False"} -SearchBase $_).count}}, @{n="10GB-Überschreitungen"; e={ getUber10 -name $_}} `| ConvertTo-Csv -Delimiter ";" -NoTypeInformation | % {$_.Replace('"','')} | Out-File C:\ExchangeReport.csv -Append$leerzeile | Out-File C:\ExchangeReport.csv -Append$leerzeile | Out-File C:\ExchangeReport.csv -Append#Liste der einzelnen Kunden mit Details der PostfächerFor($i=1; $i -lt $Kunden.Length; $i++){$Kunde=$Kunden[$i]$Uberschreit=0$anzahluber10=0$anzahl=0$UserList = Get-Mailbox -OrganizationalUnit "$Kunde" |Get-MailboxStatistics$großen = $UserList |Select TotalItemSizefor($x=0; $x -lt $großen.Length; $x++){if($großen[$x].totalItemSize.value.toMB() -gt 10000){$wieoft=$großen[$x].totalItemSize.value.toMB() * 0.0001$anzahluber10 = $anzahluber10 +  [Math]::Ceiling($wieoft) - 1}}Get-ADOrganizationalUnit -Identity $Kunden[$i] |Select-Object Name, @{n="Postfach-Anzahl";e = {(Get-ADUser -Filter {(EmailAddress -like "*@*") -and (Enabled -eq "True")} -SearchBase $Kunde).count}}`,@{n="Deaktivierte Postfächer";e = {(Get-ADUser -Filter {Enabled -eq "False"} -SearchBase $_).count}},@{n="10GB-Überschreitungen"; e={$uberschreit= $anzahluber10 ; $uberschreit}}`| ConvertTo-Csv -Delimiter ";" -NoTypeInformation | % {$_.Replace('"','')} | Out-File C:\ExchangeReport.csv -AppendGet-Mailbox -OrganizationalUnit "$Kunde" |Select-Object @{n="Kundenname";e={Get-ADOrganizationalUnit -Identity $Kunden[$i] |Select-Object Name}}, Displayname, PrimarySmtpAddress, `@{n="Size(MB)";e = {$Fachstat = Get-MailboxStatistics $_.name;$Fachstat.totalItemsize.value.toMB()}}, @{n="Quota";e={$Fachquot=Get-Mailbox $_.name;$Fachquot.ProhibitSendReceiveQuota}},` @{n="Aktiv?"; e={Get-ADUser $_.DistinguishedName |select Enabled}}, @{n="Über 10GB?"; e={$uber10 = Get-MailboxStatistics $_.name; if($uber10.totalItemSize.value.toMB() -gt 10000){$uber10.IsValid}else{$uber10.IsQuarantined}}} ` | ConvertTo-Csv -Delimiter ";" -NoTypeInformation | % {$_.Replace('"','')} | % {$_.Replace('@{Name=','')} | % {$_.Replace('}','')} | % {$_.Replace('@{Enabled=','')} | Out-File C:\ExchangeReport.csv -Append$leerzeile | Out-File C:\ExchangeReport.csv -Append$leerzeile | Out-File C:\ExchangeReport.csv -Append}$Date = Get-DAte -UFormat "%d.%m.%Y"Send-MailMessage -to "empfänger@domain.domain" -from "administrator@domain.domain" -Subject "Exchange-Report" -body "Exchange Report of $Date" -SmtpServer "External IP" -Attachments "C:\ExchangeReport.csv"Remove-Item C:\ExchangeReport.csv

I wrote the variables etc. in German, I hope thats no problem ;)