【问题标题】:Trying to create a delete email powershell script尝试创建删除电子邮件 powershell 脚本
【发布时间】:2021-10-30 04:35:49
【问题描述】:

所以我是 powershell 脚本的新手,但我正在尝试创建一个脚本,我可以根据需要对其进行调整,以从交换中删除网络钓鱼电子邮件。到目前为止,我有这个:

Import-Module ExchangeOnlineManagement
Connect-IPPSSession -UserPrincipalName xxxxxxxxxx@xxxx.com
        
New-ComplianceSearch -Name Test1 `
-ExchangeLocation All `
-ContentMatchQuery 'subject:"Informational-severity alert: eDiscovery search started or exported" AND sent:08/31/2021'
        
Start-ComplianceSearch -Identity Test1
        
Get-ComplianceSearch -Identity Test1
        
New-ComplianceSearchAction -Searchname Test1 -Purge -PurgeType Softdelete

由于合规性搜索仍在进行中,脚本一直运行到清除行。那么如何调整脚本让它等到合规性搜索完成后再对电子邮件运行清除?再说一次,我是 powershell 的初学者......所以请为我笨拙!

谢谢,

【问题讨论】:

  • 您不想在开始搜索之前 注册清除操作吗?这样搜索结果就会被清除 :-)
  • 好电话!这样就可以了,但是我在清除后开始搜索,然后执行以下操作:Get-ComplianceSearch -Identity Test3 |格式列表 * 并且我得到搜索仍在运行的错误。那么有没有办法让它等到搜索完成才能得到结果,并希望有办法将它们导出到 .csv 文件

标签: powershell exchange-server script o365security-compliance


【解决方案1】:

使用Start-Job 命令启动任务,然后运行Wait-Job 命令等待作业完成,然后继续执行脚本中的下一个命令。

来自 PowerShell 文档 Start-Job https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/start-job?view=powershell-7.1
Wait-Job https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/wait-job?view=powershell-7.1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多