Powershell统计邮箱账户信息

旧街凉风 提交于 2020-07-25 00:40:44
较早之前写的一个power shell查邮箱的脚本,可以完美的将get-mailbox和get-mailboxstatistics结合起来使用。分享给大家
注意:下面的脚本请在管理员身份的powershell ISE里面执行,执行之前先导入exchange的管理模块,导入方法是:
Add-pssnapin *exchange*
统计单个用户邮箱信息,用户名替换为要查询的用户名

ForEach($MailBox In (Get-Mailbox -ResultSize Unlimited -identity zengchuixin))
{
  Get-MailboxStatistics -Identity $MailBox | `
  Select-Object `
    @{Label="SAMAccountName";Expression={$MailBox.SAMAccountName}}, `
    @{Label="PrimarySmtpAddress";Expression={$MailBox.PrimarySmtpAddress}}, `
    @{Label="UserPrincipalName";Expression={$MailBox.UserPrincipalName}}, `
    @{Label="WhenCreated";Expression={$MailBox.WhenCreated}}, `
    @{Label="UseDatabaseQuotaDefaults";Expression={$MailBox.UseDatabaseQuotaDefaults}}, `
    @{Label="ProhibitSendReceiveQuota";Expression={$MailBox.ProhibitSendReceiveQuota}}, `
    @{Label="ProhibitSendQuota";Expression={$MailBox.ProhibitSendQuota}}, `
    @{Label="IssueWarningQuota";Expression={$MailBox.IssueWarningQuota}}, `
    @{Label="TotalItemSize(MB)";Expression={$_.TotalItemSize.value.ToMB()}}, `
    @{Label="TotalDeletedItemSize(MB)";Expression={$_.TotalDeletedItemSize.value.ToMB()}}, `
    @{Label="TotalSize(MB)";Expression={$_.TotalItemSize.value.ToMB() + $_.TotalDeletedItemSize.value.ToMB()}}, `
    ServerName,DatabaseName,DisplayName,DeletedItemCount,ItemCount,LastLogonTime,LastLoggedOnUserAccount, `
    @{Label="HiddenFromAddressListsEnabled";Expression={$MailBox.HiddenFromAddressListsEnabled}}, `
    @{Label="OrganizationalUnit";Expression={$MailBox.OrganizationalUnit}}, `
    @{Label="DistinguishedName";Expression={$MailBox.DistinguishedName}}, `
    @{Label="EmailAddresses";Expression={$MailBox.EmailAddresses}} | `
    Export-Csv -Path C:\Users\exadmin\Desktop\AllMailbox.csv -Encoding Default -NoTypeInformation
}

统计所有用户邮箱信息

ForEach($MailBox In (Get-Mailbox -ResultSize Unlimited))
{
  Get-MailboxStatistics -Identity $MailBox | `
  Select-Object `
    @{Label="SAMAccountName";Expression={$MailBox.SAMAccountName}}, `
    @{Label="PrimarySmtpAddress";Expression={$MailBox.PrimarySmtpAddress}}, `
    @{Label="UserPrincipalName";Expression={$MailBox.UserPrincipalName}}, `
    @{Label="WhenCreated";Expression={$MailBox.WhenCreated}}, `
    @{Label="UseDatabaseQuotaDefaults";Expression={$MailBox.UseDatabaseQuotaDefaults}}, `
    @{Label="ProhibitSendReceiveQuota";Expression={$MailBox.ProhibitSendReceiveQuota}}, `
    @{Label="ProhibitSendQuota";Expression={$MailBox.ProhibitSendQuota}}, `
    @{Label="IssueWarningQuota";Expression={$MailBox.IssueWarningQuota}}, `
    @{Label="TotalItemSize(MB)";Expression={$_.TotalItemSize.value.ToMB()}}, `
    @{Label="TotalDeletedItemSize(MB)";Expression={$_.TotalDeletedItemSize.value.ToMB()}}, `
    @{Label="TotalSize(MB)";Expression={$_.TotalItemSize.value.ToMB() + $_.TotalDeletedItemSize.value.ToMB()}}, `
    ServerName,DatabaseName,DisplayName,DeletedItemCount,ItemCount,LastLogonTime,LastLoggedOnUserAccount, `
    @{Label="HiddenFromAddressListsEnabled";Expression={$MailBox.HiddenFromAddressListsEnabled}}, `
    @{Label="OrganizationalUnit";Expression={$MailBox.OrganizationalUnit}}, `
    @{Label="DistinguishedName";Expression={$MailBox.DistinguishedName}}, `
    @{Label="EmailAddresses";Expression={$MailBox.EmailAddresses}} | `
    Export-Csv -Path C:\Users\exadmin\Desktop\AllMailbox.csv -Encoding Default  -append -NoTypeInformation
}

统计某一个OU下的所有邮箱用
需要修改OU的路径为自己公司要查询的OU的路径

ForEach($MailBox In (Get-Mailbox -OrganizationalUnit "OU=帐号,OU=test,DC=contoso,DC=local"  -ResultSize unlimited))
{
  Get-MailboxStatistics -Identity $MailBox.name | `
  Select-Object `
    @{Label="SAMAccountName";Expression={$MailBox.SAMAccountName}}, `
    @{Label="PrimarySmtpAddress";Expression={$MailBox.PrimarySmtpAddress}}, `
    @{Label="UserPrincipalName";Expression={$MailBox.UserPrincipalName}}, `
    @{Label="WhenCreated";Expression={$MailBox.WhenCreated}}, `
    @{Label="UseDatabaseQuotaDefaults";Expression={$MailBox.UseDatabaseQuotaDefaults}}, `
    @{Label="ProhibitSendReceiveQuota";Expression={$MailBox.ProhibitSendReceiveQuota}}, `
    @{Label="ProhibitSendQuota";Expression={$MailBox.ProhibitSendQuota}}, `
    @{Label="IssueWarningQuota";Expression={$MailBox.IssueWarningQuota}}, `
    @{Label="TotalItemSize(MB)";Expression={$_.TotalItemSize.value.ToMB()}}, `
    @{Label="TotalDeletedItemSize(MB)";Expression={$_.TotalDeletedItemSize.value.ToMB()}}, `
    @{Label="TotalSize(MB)";Expression={$_.TotalItemSize.value.ToMB() + $_.TotalDeletedItemSize.value.ToMB()}}, `
    ServerName,DatabaseName,DisplayName,DeletedItemCount,ItemCount,LastLogonTime,LastLoggedOnUserAccount, `
    @{Label="HiddenFromAddressListsEnabled";Expression={$MailBox.HiddenFromAddressListsEnabled}}, `
    @{Label="OrganizationalUnit";Expression={$MailBox.OrganizationalUnit}}, `
    @{Label="DistinguishedName";Expression={$MailBox.DistinguishedName}}, `
    @{Label="EmailAddresses";Expression={$MailBox.EmailAddresses}} | `
    Export-Csv -Path C:\Users\exadmin\Desktop\public.csv -Encoding Default -append -NoTypeInformation
}

欢迎扫描关注本人的微信公众号,获取更多IT资讯:


87ca485f12aba14fe32378b978daebb4.jpg

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!