搜尋此網誌

2017年7月28日 星期五

利用Exchange management powershell下指令,自動刪除帳號大於30天前的資料Delete a users emails older than X days

Delete a users emails older than X days
如果exchange管理者想每天自動刪除某些帳號X天以前的email要如何做呢?

指令1:刪除30天前的帳號USERNAME內容
$Today = (Get-Date).adddays(-30).ToString("MM/dd/yyyy") ; Search-Mailbox USERNAME -SearchQuery "Received:$Today" -deleteContent -force

指令2:刪除10天前的帳號administrator內容
$Today = (Get-Date).adddays(-10).ToString("MM/dd/yyyy") ; Search-Mailbox administrator -SearchQuery "Received:$Today" -deleteContent -force

指令3:刪除10天前屬於Ann帳號 email的內容,不會刪除到連絡人、行事曆內容
$Today = (Get-Date).adddays(-10).ToString("MM/dd/yyyy") ; Search-Mailbox ann -SearchQuery "Received:$Today AND kind:email" -deleteContent -force

指令4:刪除12天前屬於Ann帳號 email及行事曆的內容不會刪除到連絡人
$Today = (Get-Date).adddays(-12).ToString("MM/dd/yyyy") ; Search-Mailbox ann -SearchQuery "Received:$Today AND (kind:email OR kind:meetings)" -deleteContent -force


如何在排程中下這些指令呢?
PowerShell.exe -command ". 'D:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; D:\administrator-30day.ps1"

kind指令要如何下呢??請參考Advanced Query Syntax (AQS)

其它參考資料:
How to delete email from mailboxes on Exchange 2016 / 2013 / 2010 / Online
Search-mailbox restricted to single sub-folder
Powershell/Exchange - Delete a users emails older than X days and X size




沒有留言:

張貼留言