Today, customers are asked to get some basic information about mailbox users, one of which is mailbox capacity usage. I needed to use PowerShell to get this information in bulk, so I started writing PowerShell scripts.
I understand that Microsoft official website https://gallery.technet.microsoft.com/scriptcenter/Exchange-2010-2013-2016-cee5e558. This script is provided, the functionality of the script implementation is broadly consistent with the functionality I need to implement, and I don't have to bother writing code from scratch. Below I will share my modified script to everyone.
1, the function of the script implementation
Script mailbox user's script bulk to get information about the mailbox user (display name, login name, ou information, mailbox quotas, number of mailbox messages, mailbox used size, email address, mailbox capacity usage, and more)
2. Script running Environment
Currently the script can be used to get Exchange 2010/2013. As for Exchange 2016, it is not yet tested.
3, fixed the following deficiencies in the original script:
1), repair the display name contains Chinese when the display garbled problem.
2) added a decision when the user's mailbox is set to a custom quota and the custom quota is set to unlimited, the script automatically determines the condition.
3), added calculated user mailbox usage (percentage).
4), add the user mailbox quota is set to the database quota, and the database quota is set to unrestricted, the script automatically judge the condition.
4. Script content:
#--------------------------------------------below for the script body content, directly copy the following content, Then save As. PS1-------------------------------------------------
Param (
[Parameter (Mandatory = $true)]
[String] $CSVPath
)
$Mailboxes = Get-mailbox-resultsize Unlimited
$CSV = @ ()
foreach ($Mailbox in $Mailboxes)
{
$MailboxStats = (get-mailboxstatistics $Mailbox-warningaction silentlycontinue)
if ($mailbox. Usedatabasequotadefaults-eq $true)
{
if (Get-mailboxdatabase $mailbox. Database). Prohibitsendreceivequota.value-eq $null)
{
$ProhibitSendReceiveQuota =0
}
if (Get-mailboxdatabase $mailbox. Database). Prohibitsendreceivequota.value-ne $null)
{
$ProhibitSendReceiveQuota = (Get-mailboxdatabase $mailbox. Database). ProhibitSendReceiveQuota.Value.ToMB ()
}
}
if ($mailbox. Usedatabasequotadefaults-eq $false)
{
if ($mailbox. Prohibitsendreceivequota.value-eq $null)
{
$ProhibitSendReceiveQuota =0
}
if ($mailbox. Prohibitsendreceivequota.value-ne $null)
{
$ProhibitSendReceiveQuota = $mailbox. ProhibitSendReceiveQuota.Value.ToMB ()
}
}
$CSVLine = New-object System.Object
$CSVLine | Add-member-type noteproperty-name "DisplayName"-value $Mailbox. DisplayName
$CSVLine | Add-member-type noteproperty-name "UserName"-value $Mailbox. sAMAccountName
$CSVLine | Add-member-type noteproperty-name "Primarysmtp"-value $Mailbox. windowsemailaddress
$CSVLine | Add-member-type noteproperty-name "organizationalunit"-value $Mailbox. organizationalunit
$CSVLine | Add-member-type noteproperty-name "emailaliases"-value ($Mailbox. Emailaddresses.smtpaddress-join ";")
if ($MailboxStats)
{
if ($ProhibitSendReceiveQuota-eq 0)
{
$CSVLine | Add-member-type noteproperty-name "TOTALITEMSIZEINMB"-value $MailboxStats. TotalItemSize.Value.ToMB ()
$CSVLine | Add-member-type noteproperty-name "ItemCount"-value $MailboxStats. ItemCount
$CSVLine | Add-member-type noteproperty-name "Storagelimitstatus"-value $Mailbox. Storagelimitstatus
$CSVLine | Add-member-type noteproperty-name "Usedatabasequotadefaults"-value $Mailbox. Usedatabasequotadefaults
$CSVLine | Add-member-type noteproperty-name "PROHIBITSENDRECEIVEQUOTAINMB"-value "no quota limit for this user"
$CSVLine | Add-member-type noteproperty-name ' mailbox usage (%) '-value "This user has no quota limit"
}
if ($ProhibitSendReceiveQuota-ne 0)
{
$CSVLine | Add-member-type noteproperty-name "TOTALITEMSIZEINMB"-value $MailboxStats. TotalItemSize.Value.ToMB ()
$CSVLine | Add-member-type noteproperty-name "ItemCount"-value $MailboxStats. ItemCount
$CSVLine | Add-member-type noteproperty-name "Storagelimitstatus"-value $Mailbox. Storagelimitstatus
$CSVLine | Add-member-type noteproperty-name "Usedatabasequotadefaults"-value $Mailbox. Usedatabasequotadefaults
$CSVLine | Add-member-type noteproperty-name "PROHIBITSENDRECEIVEQUOTAINMB"-value $ProhibitSendReceiveQuota
$UsedSpace =[int] ($MailboxStats. TotalItemSize.Value.ToMB () *100/$ProhibitSendReceiveQuota)
$CSVLine | Add-member-type noteproperty-name ' mailbox usage (%) '-value ("$UsedSpace" + "%")
}
}
$CSV + = $CSVLine
}
$CSV | Sort totalitemsize-descending | Export-csv-notypeinformation $CSVPath-encoding Unicode
#-------------------------------------end of script content----------------------------------------------------------------------------- -------------------------------------
5. How to use the script
Copy the script content after the Save As. PS1 format (for example: New-mailboxsizereport-02.ps1. Use Exchange PowerShell to execute the script on Exchange.
650) this.width=650; "title=" image "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" image "src=" http://s3.51cto.com/wyfs02/M02/7F/7C/ Wkiom1cgttfgpnafaaasha30480893.png "520" height= "Wuyi"/>
Because the time relationship does not optimize the execution efficiency of the script, interested children's shoes can be studied.
Use PowerShell to bulk get Exchange 2013 mailbox user capacity usage