Powershell统计邮箱账户信息
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Powershell统计邮箱账户信息相关的知识,希望对你有一定的参考价值。
较早之前写的一个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 统计邮箱容量-Powershell
Exchange Server 2016管理系列课件02.创建邮箱方法详解
sql Powershell Migration工具http://stackingcode.com/blog/2011/10/12/database-migrations-with-powershel
powershell 来自https://stackoverflow.com/questions/31051103/how-to-export-a-class-in-powershell-v5-mod