Удалите все электронные письма в PowerShell старше 7 месяцев без использования Search-Mailbox - PullRequest
0 голосов
/ 04 августа 2020

У меня проблема с преобразованием моей команды Search-Mailbox в другую. Если вы все знаете, в будущем как Search-Mailbox на пенсии. Поэтому мне нужно использовать другой командлет для этой команды.

Вот моя Search-Mailbox команда:

Search-Mailbox -Identity test@test.comm -SearchQuery "(Received:01/12/2017..$((get-date).AddMonths(-7).ToString("MM/dd/yyy")))" -deletecontent

То, что я пытаюсь сделать:

    New-ComplianceSearch -Name "Remove older than 7 month messages" -ExchangeLocation test@test.com  -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 7 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.
> + CategoryInfo          : WriteError: (:) [New-ComplianceSearchAction], ComplianceJobTaskException

Это то, что я пытаюсь. Пожалуйста, помогите мне с этой проблемой, я очень застрял здесь прямо сейчас.

если я просто запустил это:

New-ComplianceSearch -Name "Remove older than 8 month messages" -ExchangeLocation research.shared@covaliscapital.com  -ContentMatchQuery "(Received:01/12/2017..$((get-date).AddMonths(-8).ToString("MM/dd/yyy")))"
Start-ComplianceSearch -Identity "Remove older than 8 month messages"

я получаю это

 RunspaceId                            : sagasgasgasgagsa
    Language                              :
    StatusMailRecipients                  : {}
    LogLevel                              : Suppressed
    IncludeUnindexedItems                 : True
    ContentMatchQuery                     : (Received:01/12/2017..12/04/2019)
    SearchType                            : EstimateSearch
    HoldNames                             : {}
    SearchNames                           : {}
    RefinerNames                          : {}
    Region                                :
    Refiners                              :
    Items                                 : 0
    Size                                  : 0
    UnindexedItems                        : 0
    UnindexedSize                         : 0
    SuccessResults                        : {}
    SearchStatistics                      :
    Errors                                :
    ErrorTags                             : {}
    NumFailedSources                      : 0
    JobId                                 : gasgsagasgasgsagasg
    Name                                  : Remove older than TEST month messages
    CreatedTime                           : 8/4/2020 10:49:45 AM
    LastModifiedTime                      : 8/4/2020 10:49:45 AM
    JobStartTime                          :
    JobEndTime                            :
    Description                           :
    CreatedBy                             : IT Support
    RunBy                                 :
    TenantId                              : asgasgagasgsa
    NumBindings                           : 0
    Status                                : NotStarted
    ExchangeLocation                      : {TEST@TEST.com}
    PublicFolderLocation                  :
    SharePointLocation                    :
    OneDriveLocation                      :
    ExchangeLocationExclusion             :
    PublicFolderLocationExclusion         :
    SharePointLocationExclusion           :
    OneDriveLocationExclusion             :
    JobRunId                              : asgasgag
    Retry                                 : False
    AllowNotFoundExchangeLocationsEnabled : False
    JobOptions                            : 0
    JobProgress                           : 0
    CaseId                                :
    CaseName                              :
    PagingState                           :
    Identity                              : dsaasgfasgsagga
    ContentURL                            :
    ResultInEOP                           : False
    AzureBatchFrameworkEnabled            : False
    IsValid                               : True
    ObjectState                           : New

Мой полный сценарий PowerShell

Start-Transcript


$smtpServer="smtp.office365.com" # Office 365 official smtp server 
$from = "IT Support <test@test.com>" # email from  
$logging = "Enabled" # Set to Disabled to Disable Logging 
$testing = "Disabled" # Set to Disabled to Email Users 
$testRecipient = "test@test.com"  
$date = Get-Date -format ddMMyyyy 

$Username = "test@test.com"
$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 test@test.com  -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 
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...