码迷,mamicode.com
首页 > 系统相关 > 详细

Powershell统计邮箱账户信息

时间:2017-04-04 18:00:50      阅读:264      评论:0      收藏:0      [点我收藏+]

标签:powershell   exchange 2013   统计邮箱信息   

较早之前写的一个power shell查邮箱的脚本,可以完美的将get-mailbox和get-mailboxstatistics结合起来使用。分享给大家
统计单个用户邮箱信息,用户名替换为要查询的用户名

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 -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
}

本文出自 “曾垂鑫的技术专栏” 博客,谢绝转载!

Powershell统计邮箱账户信息

标签:powershell   exchange 2013   统计邮箱信息   

原文地址:http://543925535.blog.51cto.com/639838/1912791

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!