troubleshooting Question

Powershell Search and Delete Commands

Avatar of Christopher Bruder
Christopher BruderFlag for United States of America asked on
ExchangeMicrosoft 365Powershell
2 Comments1 Solution54 ViewsLast Modified:
Microsoft is retiring some of the powershell commands I use to connect and to search/delete emails from mailboxes.  I'm trying to find the replacement commands but can't seem to 'string' them together.  Can someone help me?

This is part of me connecting:
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.of
fice365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
WARNING: Using New-PSSession with Basic Authentication is going to be deprecated soon, checkout
https://aka.ms/exops-docs for using Exchange Online V2 Module which uses Modern Authentication.

This is how I search and get an estimate or delete mail:
Search-Mailbox -Identity user@mycompany.com -SearchQuery 'SUBJECT:"[EXTERNAL] Subject Here" AND FROM:externalperson@externalcompany.com' -DeleteContent
WARNING: WARNING:  On July 1, 2020, the Search-Mailbox cmdlet is being retired and Microsoft Support will no longer
provide assistance.  See https://go.microsoft.com/fwlink/?linkid=2113221 to learn more.
WARNING: The Search-Mailbox cmdlet returns up to 10000 results per mailbox if a search query is specified. To return
more than 10000 results, use the New-MailboxSearch cmdlet or the In-Place eDiscovery & Hold console in the Exchange
Administration Center.
In the above command, I will also sometimes use -EstimateResultOnly.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros