I'm trying to write a PowerShell script using MSGraphConnector to find specific emails by their subject line and then delete them from mailboxes. However, I'm running into an error when using Connect-MgGraph: it says it can't bind the 'ClientSecretCredential' parameter because it can't convert my secret key string into the required type. I've spent too long on this and figured there must be a better way to do it in Exchange. I don't have Defender for Office 365. Can anyone assist me?
5 Answers
You could also just throw your question into ChatGPT; it might spit out a quick solution for you!
You should look into eDiscovery and check out the command **New-ComplianceSearchAction -Purge**. You can use this command even without Defender, but make sure you have the Compliance Administrator role in your M365 tenant.
You can actually use Purview Content Search for this. It’s a solid way to search and manage emails without needing to dig too deep into PowerShell.
If you're scripting, using the dedicated PowerShell cmdlets for Purview content searches is likely the simplest approach. Otherwise, just hop on the Purview website for guidance on how to search mailbox data.
Honestly, I’d skip PowerShell altogether for this. Just go with eDiscovery; it’s much easier to handle.
Right, the Defender isn't necessary, but just to add, having the right permissions is key to making this work.