Exchange - listing mailboxes in an organizational unit with their mailbox size

I am trying to display all mailboxes and their sizes for all of our users in our branch office. I seem to be very close, but my team seems to be adding some additions to the results.

[PS] C:\Windows\system32>dsquery user "ou=Departed,ou=Staff,dc=COMPANY,dc=local" -limit 4 | dsget user -samid | Get-MailboxStatistics | ft DisplayName, TotalItemSize, ItemCount

      

And the output is:

Dsquery has reached the specified limit on number of results to display; use a different value for the -limit option to
display more results.The specified mailbox "  samid                 " doesn't exist.
    + CategoryInfo          : NotSpecified: (0:Int32) [Get-MailboxStatistics], ManagementObjectNotFoundException
    + FullyQualifiedErrorId : DD7D7CEA,Microsoft.Exchange.Management.MapiTasks.GetMailboxStatistics

The specified mailbox "  Eka.Tian              " doesn't exist.
    + CategoryInfo          : NotSpecified: (1:Int32) [Get-MailboxStatistics], ManagementObjectNotFoundException
    + FullyQualifiedErrorId : 7F701DFD,Microsoft.Exchange.Management.MapiTasks.GetMailboxStatistics

      

Obviously shouldn't work for the first "samid" result, but "Eka.Tian" exists. Why is he adding all these spaces? Is there a way that I could format the output from the dsget user so that it works fine with Get-MailboxStatistics?

+3


source to share


2 answers


Why dsquery?



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

      

+11


source


I have something for you, although it's a little late. You just need to set up each search base with an OU and DC, email addresses at the end and an SMTP server, then you will receive an email with a CSV attachment that contains each department with the number of active and inactive mailboxes and a list with each mailbox and its parameters. You can also run it using Windows Task Scheduler, so it is 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 Kontrolle
function getUber10 ($name)
{
$Uberschreit=0
$anzahluber10=0
$anzahl=0
$UserList = Get-Mailbox -OrganizationalUnit "$name" |Get-MailboxStatistics
$großen = $UserList |Select TotalItemSize
for($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 Postfachanzahl
Get-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ächer
For($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 TotalItemSize
for($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 -Append

Get-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 variables, etc. in German, hopefully this is not a problem;)

0


source







All Articles