I said no Confirm…..

So I have been pulled away from Powershell (at least in day to day work) and getting back into it on a project by project basis. Yeah I miss it. Enough of that…

So another product I am getting back to is Exchange. Even better is as I have moved into the Exchange team, the product (currently using 2010) has some decent Powershell modules. I do find them weak in a forest and the documentation is far from what he have been used to with Powershell. I was able to work on a few scripts for the migration, one of them was dealing with shared calendars, sadly eventhough the script updated permissions it was documented that you still needed to open each mailbox and set calendar permissions…..

Onto another usage. How can you delete an email from mulitple mailboxes? Search-mailbox is the answer. Again the documentation (http://technet.microsoft.com/EN-US/library/9ee3b02c-d343-4816-a583-a90b1fad4b26(EXCHG.141).aspx ) is a little lacking especially for the most important parameter, SearchQuery. I started by using my mailbox as the test case (not to mention it was a good way to clean up my mailbox) and came up with:

get-mailbox someaccount-domaincontroller somedc |
search-mailbox-SearchQuery‘From:”someuser@nodomain.com”‘-deletecontent-confirm:$False

Looks good, hey what is this Confirm prompt? I said no to that. So then I tested without the confirm parameter… okay setting it to false stopped some confirmation prompts but not all. I need to run this against mutliple mailboxes, I don’t want to require someone to man the process and type A with each mailbox… Let’s try something else. The winner:

get-mailbox someaccount-domaincontroller somedc |
search-mailbox -SearchQuery ‘From:”someuser@nodomain.com”‘ -deletecontent -confirm:$False -Force

Adding the Force parameter suppresses all confirmation prompts, mission accomplished.