我在将Search-Mailbox
命令转换为另一个命令时遇到了问题。如果你们都知道,将来它就会Search-Mailbox
被淘汰。所以我需要为这个命令使用另一个 cmdlet。
我现在的工作命令是Search-Mailbox
Search-Mailbox -Identity [email protected] -SearchQuery "(Received:01/12/2017..$((get-date).AddMonths(-7).ToString("MM/dd/yyy")))" -deletecontet
我读了很多遍https://docs.microsoft.com/en-us/exchange/policy-and-compliance/ediscovery/delete-messages?view=exchserver-2019#step-2-delete-the-message并尝试一步一步操作并获取此代码。
New-ComplianceSearch -Name "Remove older than 7 month messages" -ExchangeLocation [email protected] -ContentMatchQuery "(Received:01/12/2017..$((get-date).AddMonths(-7).ToString("MM/dd/yyy")))"
Start-ComplianceSearch -Identity "Remove older than 7 month messages"
New-ComplianceSearchAction -SearchName "Remove older than 7 month messages" -Purge -PurgeType SoftDelete
但它对我来说不起作用。出现错误
Unable to execute the task. Reason: The search "Remove older than 8 month messages" is still running or it didn't
return any results. Please wait until the search finishes or edit the query and run the search again.
添加我的完整 PowerShell 脚本
Start-Transcript
$smtpServer="smtp.office365.com" # Office 365 official smtp server
$from = "IT Support <[email protected]>" # email from
$logging = "Enabled" # Set to Disabled to Disable Logging
$testing = "Disabled" # Set to Disabled to Email Users
$testRecipient = "[email protected]"
$date = Get-Date -format ddMMyyyy
$Username = "[email protected]"
$Password = "test-" | ConvertTo-SecureString -AsPlainText -Force
$UserCredential = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$Password
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://eur04b.ps.compliance.protection.outlook.com/powershell-liveid?PSVersion=5.1.17763.1007 -Credential $UserCredential -Authentication Basic –AllowRedirection
Import-PSSession $Session
Get-ComplianceSearchAction
New-ComplianceSearch -Name "Remove older than 7 month messages" -ExchangeLocation [email protected] -ContentMatchQuery "(Received:01/12/2017..$((get-date).AddMonths(-7).ToString("MM/dd/yyy")))"
Start-ComplianceSearch -Identity "Remove older than 7 month messages"
New-ComplianceSearchAction -SearchName "Remove older than 7 month messages" -Purge -PurgeType SoftDelete
答案1
尝试:
New-ComplianceSearch -Name "Remove older than 7 month messages" -ExchangeLocation [email protected] -ContentMatchQuery "(Received >= 01/12/2017 -and Received <= $((get-date).AddMonths(-7).ToString("MM/dd/yyy")))"