本文共 4978 字,大约阅读时间需要 16 分钟。
较早之前写的一个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资讯:
转载地址:http://nopla.baihongyu.com/