I am new to powershell scripting and I am trying to create a script that I can tweak as needed to delete phishing emails from exchange.
So far I have this:
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
The script works up until the purge line due to the fact that the compliance search is still in progress. So how can I adjust the script to have it wait until the compliance search is complete before running the purge on the emails? Again, I am very much a beginner at powershell, so take that into consideration when writing an answer, please!