PowerShell – auxiliary script to populate CustomAttribute10 with a Purged Items FolderID

Originally this script ( New-ComplianceSearch script ) would search through Purged Items. That was the downside of it comparing to a "classic" Search-Mailbox you can find here ( Search-Mailbox script ). So imagine you run the script the 1st time, find target messages, and then delete them - the found results make sense. However, should you run the script the 2nd time with the same search criteria, it would find those already purged messages again. That creates some confusion. So it would be great to exclude Purged Items folders from the search. Now, it is possible to do so on the fly ( https://docs.microsoft.com/en-us/microsoft-365/compliance/use-content-search-for-targeted-collections ) but it is very time consuming and takes about 1-3 seconds for each mailbox which stacks up pretty fast. So I came up with a script to take care of this issue by storing a Purged Items FolderID in a CustomAttribute10 of each mailbox. So…

Continue ReadingPowerShell – auxiliary script to populate CustomAttribute10 with a Purged Items FolderID

PowerShell – New-ComplianceSearch script to go through all mailboxes, find a target message, and remove it

Here is another more advanced script that searches for messages of interest, then optionally exports and purges them. So, what makes this script more advanced? Unlike the other script that uses Search-Mailbox ( https://365basics.com/powershell-search-mailbox-script-to-go-through-all-mailboxes-find-a-target-message-and-remove-it/ ) this script below is based on New-ComplianceSearch cmdlet: Pros: Super fast, multi-threaded, takes about 1-2 minutes on average to complete the whole task. As Microsoft is trying to depreciate Search-Mailbox, they put more effort into New-ComplianceSearch, so we can expect new functionality to come in the future. Can create an export file that can be downloaded and investigated. Cons: Always searches through all folders including Purged Items which might create some confusion when showing results (if running the same search again) - see UPDATE 9/30/2019 Cannot copy messages to another mailbox for you to investigate. Of course there are quite a few scripts out there that use New-ComplianceSearch, everyone has their own approach. So let…

Continue ReadingPowerShell – New-ComplianceSearch script to go through all mailboxes, find a target message, and remove it

PowerShell – Search-Mailbox script to go through all mailboxes, find a target message, and remove it

When looking at the title of this post, one might notice I used a target word, and it is on purpose. This script below is useful when trying to remove all types of messages from users' mailboxes whether it's a spam, scam, virus or a an important message that needs to be "recalled". This script is based on Search-Mailbox cmdlet, works well but it has its own pros and cons, more on some of them below. Later I will have another post showing a different and more advanced script to do the same and even better. So stay tuned. Pros: Doesn't search through Purged Items (a bit more about the 3rd layer of Trash is here - https://365basics.com/script-to-search-through-recoverable-and-purged-items-and-restore-those/ ). Can copy messages to another mailbox (IT Help in that example). Cons: Per Microsoft Search-Mailbox will be depreciated, we don't know when it will happen though. Slow (if a target message…

Continue ReadingPowerShell – Search-Mailbox script to go through all mailboxes, find a target message, and remove it