一些EXCHANGE命令

煙臺小崔 的BLOGhttp://seawind.blog.51cto.com/6845370/1883317

2016-12-16 14:10:09

標籤:EXCHANGE命令

原創作品,允許轉載,轉載時請務必以超鏈接形式標明文章 原始出處 、作者信息和本聲明。否則將追究法律責任。http://seawind.blog.51cto.com/6845370/1883317

1.獲取所有郵箱使用情況,按大小排序輸出到磁盤

Get-Mailbox | Get-Mailboxstatistics | Sort-Object TotalItemSize -Descending | ft DisplayName,@{label="TotalItemSize(KB)";expression={$_.TotalItemSize.Value.ToKB()}},ItemCount >d:\1.csv


2.通過用戶名找GUID:

get-mailbox -identity "用戶名" | fl name,guid


3.批量查找所有用戶的GUID:

get-mailbox | fl name,guid


4.獲取郵箱配額設置:

Get-Mailbox -identity "用戶名" | fl IssueWarningQuota,ProhibitSendQuota,ProhibitSendReceiveQuota


5.提升對指定數據庫中的所有用戶的操作權限:

get-mailbox -Database "數據庫名" | add-mailboxpermission -user 域名\administrator -Acce***ights FullAccess -InheritanceType all


6.按主題包含的關鍵字刪除:

Search-Mailbox -Identity lisi -SearchQuery  "Subject:關鍵字" -DeleteContent

例如:

Search-Mailbox -Identity lisi -searchquery  主題: 報價 -deletecontent


7.批量刪除:
get-mailbox -Database "數據庫名" | Search-Mailbox -DeleteContent


8.獲取已經創建的郵箱:

Get-Mailbox | FL Name,RecipientTypeDetails,PrimarySmtpAddress


9.批量啓用郵箱帳戶:

啓用AD中所有未啓用的用戶:

Get-User -RecipientTypeDetails User -Filter { UserPrincipalName -ne $Null } | Enable-Mailbox -Database "數據庫名稱"


10.啓用AD中某個組織單位下面的用戶:

Get-User -OrganizationalUnit "組織單位名稱" | Enable-Mailbox -Database "數據庫名稱"



11.查看郵件服務器上某個時間段內的所有郵件信息:

Get-MessageTrackingLog -ResultSize Unlimited -Start "3/6/2016 8:40AM" -End "3/6/2016 1:50PM"


12.查看郵件服務器上某個時間段內由具體的某個人所發送的所有郵件詳細信息:

Get-MessageTrackingLog -ResultSize Unlimited -Start "3/6/2016 8:40AM" -End "3/6/2016 1:50PM" –Sender [email protected]

後面加上 | fl 則顯示每封郵件的詳細信息。


13.查詢發送失敗的郵件

Get-MessageTrackingLog -ResultSize Unlimited -Start "3/6/2016 8:40AM" -End "3/6/2016 2:50PM" -EventId "Fail" -Sender [email protected]


14.刪除羣發郵件


Get-Mailbox –ResultSize unlimited | Search-Mailbox -searchquery 主題:測試郵件 –deletecontent


15.通過時間篩選刪除郵件


Search-Mailbox -Identity lisi -SearchQuery "發送時間:<2016/12/16"-deletecontent

Search-Mailbox -Identity lisi -SearchQuery "發送時間:=2016/12/16"-deletecontent

Search-Mailbox -Identity lisi -SearchQuery "發送時間:>2016/12/16"-deletecontent

Search-Mailbox -Identity lisi -SearchQuery "發送時間:<2016/12/11 and 2016/12/16" –deletecontent


16.查找服務器中已斷開連接的郵箱

Get-MailboxDatabase | Get-MailboxStatistics | where {$_.DisconnectReason -ne $null} | ft displayname,database,disconnectreason -auto


找不到的話執行下第 17清理郵箱數據庫,再查找。



17.清理郵箱數據庫(E2013/16)


Get-MailboxStatistics -Database "Database name" | ForEach { Update-StoreMailboxState -Database $_.Database -Identity $_.MailboxGuid -Confirm:$false }


18.批量導出所有郵件

$users=get-content -path "c:\user.txt"foreach($i in $users){New-MailboxExportRequest -Mailbox $i -FilePath "\\ServerName\PST\$($i).pst" –ExcludeFolders “DeletedItems” –ExcludeDumpster  -BadItemLimit 1000 -AcceptLargeDataLoss} 


19.批量導出單個數據庫中所有郵箱的郵件

Get-Mailbox -DataBase DBName |ForEach-Object {New-MailboxExportRequest -Mailbox $_ -FilePath "D:\Newfolder\$($_.Alias).pst" –ExcludeFolders “DeletedItems” –ExcludeDumpster  -BadItemLimit 1000 -AcceptLargeDataLoss }


20.EX13/16 限制用戶每天接收、發送郵件的數量


  1. New-ThrottlingPolicy -Name LimitMessagesSent -RecipientRateLimit 300 -MessageRateLimit 10

    以上命令,傳輸策略的名稱爲:limitmessagessent,可以接收的數量:300,可以發送的數量:10.

  2. Set-Mailbox -Identity 用戶名 -ThrottlingPolicy LimitMessagesSent  (應用到具體郵箱上面)



21.查找所有郵箱並按照使用空間大小來排序並按照指定字段顯示


Get-Mailboxdatabase |Get-Mailboxstatistics |sort totalitemsize -desc |ft
displayname,itemcount 


22.獲取郵箱數據庫的路徑,按要求輸出


get-mailboxdatabase | fl name,*path*

wKioL1hiDfjCj4LwAAA0ZWkhOAE576.png-wh_50



23.設置用戶收發郵件的大小,設置發送、接受連接器大小


設置所有用戶:

get-user | set-mailbox -maxsendsize "20MB" -maxreceivesize "20MB"


以上命令會遍歷所有郵箱,運行時用戶郵箱完成配置,但系統郵箱等會報錯。可用以下命令跳過:


Get-Mailbox -ResultSize unlimited -Filter{(RecipientTypeDetails -eq"UserMailbox")} | Set-Mailbox -MaxSendSize 20mb -MaxReceiveSize 20mb


清除現有所有用戶單獨設置的收發郵件大小值(無限制):


Get-Mailbox -ResultSize unlimited -Filter{(RecipientTypeDetails -eq "UserMailbox")}| Set-Mailbox -MaxSendSize Unlimited -MaxReceiveSize Unlimited


查詢當前傳輸設置、發送連接器、接收連接器設置:

Get-TransportConfig |ft maxsendsize,maxreceivesize

Get-ReceiveConnector |ft name,maxmessagesize

Get-SendConnector |ft name,maxmessagesize



設置傳輸連接器大小:

Set-TransportConfig -MaxSendSize 35MB -MaxReceiveSize 35MB



設置發送連接器大小:

Get-SendConnector | Set-SendConnector -MaxMessageSize 35MB


查看用戶郵箱收發郵件大小:

Get-Mailbox  123 | fl MaxSendSize,MaxReceiveSize



設置某個用戶郵箱收發郵件大小:

Set-Mailbox 123 -MaxSendSize 10mb -MaxReceiveSize 10mb


24.去除匿名中繼的權限(去除仿冒內部郵件地址)
==========
Get-ReceiveConnector "Internet Receive Connector" | Remove-ADPermission -User "NT AUTHORITY\ANONYMOUS LOGON" -ExtendedRights "Ms-Exch-SMTP-Accept-Any-Recipient"
 
25.去除接收匿名郵件域發送者的權限(對過濾垃圾郵件有一定作用)
==========
Get-ReceiveConnector "Internet Receive Connector" | Remove-ADPermission -User "NT AUTHORITY\ANONYMOUS LOGON" -ExtendedRights "ms-exch-smtp-accept-authoritative-domain-sender"


26.查看某一個郵箱的統計信息(最後登錄時間等)

Get-MailboxStatistics -Identity 'administrator' |fl


27.查看某個郵箱服務器上所有用戶的統計信息,例如在這裏範例需要查看郵件服務器 tr-ex01 上相關用戶的登錄時間,可以輸入如下內容:

Get-MailboxStatistics -server 'tr-ex01'



28.查看某個郵箱服務器上所有用戶的統計信息,並且以降序排列,例如在這裏範例需要查看郵件服務器 tr-ex01 上相關用戶的登錄時間並且以降序方式排列,可以輸入如下內容:

Get-MailboxStatistics -server 'tr-ex01' | Sort LastLogonTime -Descending


29.查詢一段時間的  每個用戶的郵件發送數量

 

Get-MessageTrackingLog -ResultSize unlimited -Start"07/01/2012" -End "07/13/2012" -EventId "send"|Group-Object -Property:sender |Select name,count|sort count -Descending   

如果不想要外部郵箱的話,加一個filter

 

Get-MessageTrackingLog -ResultSize Unlimited -Start"10/1/2013" -End "10/25/2013" | where{$_.recipients -like"*@domain.com"}

 

如果是要查發出的,就把recipients改成sender


30.本示例返回貴組織中所有郵箱的摘要列表


Get-Mailbox -ResultSize unlimited


31.返回組織內名爲 Users 的 OU 中所有郵箱的列表

Get-Mailbox -OrganizationalUnit Users


32.查詢ex  郵箱服務器  上面所有存檔郵箱的列表

get-mailbox -archive -server ex


32.查詢mailbox1  郵箱數據庫  上面所有存檔郵箱的列表


get-mailbox -archive -database mailbox1


33.查詢所有的郵箱數量

 (get-mailbox-resultsize unlimited).count 


34.查詢每個郵箱數據庫中分別有多少用戶

get-mailbox-resultsize unlimited | group-object -property:database | select-objectname,count 

如果把database參數更替爲郵箱數據庫的名字,那統計出來的就是某一個郵箱數據庫內的用戶數量


35.查詢每個郵箱服務器上面分別有多少用戶


get-mailbox-resultsize unlimited | group-object -property:servername | select-object name,count 

如果把 servername參數更替爲服務器的名字,那統計出來的就是某一個郵箱服務器內的用戶數量


36.批量導出、導入郵箱

     1.賦予管理員權限

 New-ManagementRoleAssignment -Name "ImportExport_Domain Admins" -User        "Administrator" -Role "MailboxImport Export"

      
     2.批量導出郵件到C盤EXPORT文件夾下 

get-mailbox -OrganizationalUnit "contoso.com/contoso" -resultsize unlimited |%{New-MailboxexportRequest -mailbox $_.name -FilePath ("\\localhost\c$\export\"+($_.name)+".pst") -BadItemLimit50}


     3. 批量導入PST文件到目的郵箱地址

get-childitem\\localhost\c$\export\*.pst | select name,basename | %{New-MailboximportRequest-mailbox $_.basename -FilePath ("\\localhost\c$\export\"+$_.name)-BadItemLimit 50}



37.查找用戶的GUID


get-mailbox -identity "用戶名" | fl name,guid


38.查找所有用戶的GUID

get-mailbox | fl name,guid



39.獲取郵箱使用情況,按大小排序輸出到磁盤

Get-Mailbox | Get-Mailboxstatistics | Sort-ObjectTotalItemSize -Descending | ftDisplayName,@{label="TotalItemSize(KB)";expression={$_.TotalItemSize.Value.ToKB()}},ItemCount>d:\1.csv



40.獲取某個用戶的郵箱配額(警告、阻止、阻止發送接收):

Get-Mailbox -identity  "用戶名" | fl IssueWarningQuota,ProhibitSendQuota,ProhibitSendReceiveQuota


41.提升指定數據庫中的所有用戶的操作權限爲administrator


get-mailbox -Database "數據庫名" | add-mailboxpermission -user域名\administrator -Acce***ights FullAccess -InheritanceTypeall




42.批量啓用郵箱賬戶


啓用AD中所有未啓用的用戶:


Get-User -RecipientTypeDetails User -Filter { UserPrincipalName -ne $Null} | Enable-Mailbox -Database  "數據庫名稱"

 

啓用AD中某個組織單位下面的用戶:


Get-User -OrganizationalUnit  "組織單位名稱" | Enable-Mailbox -Database  "數據庫名稱"


43、查看每個賬戶設備的連接數量

 Get-MobileDeviceStatistics -Mailbox 用戶名 | fl deviceid


44.開啓或關閉NDR(未送達報告)

Set-RemoteDomain contoso -NDREnabled $false
Set-RemoteDomain Contoso -NDREnabled $true


45.導入、導出郵箱


new-mailboxexportrequest -mailbox zhangsan -filepath \\****\\mailbox.pst

new-mailboximportrequest  -mailbox zhangsan -filepath \\***\mailbox.pst

導入導出路徑必須爲UNC路徑,導出爲PST格式可以直接用OUTLOOK掛載進行查看。


46.郵件跟蹤命令


  1. 查看用戶發送和接收郵件的記錄

    get-messagetrackinglog -sender [email protected]

    get-messagetrackinglog -recipients [email protected]

  2. 查看zhangsan發往lisi的郵件記錄

    get-messagetrackinglog -sender [email protected] -recipients [email protected]

  3. 查看某個發送週期內的發送記錄

    get-messagatrackinglog -sender [email protected] -recipients [email protected] -start "2017-06-01 -end "2017-07-11"



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章