首页 > 代码库 > Powershell统计邮箱账户信息
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统计邮箱账户信息
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。