Install and connect to the Compliance Center:
Install-Module ExchangeOnlineManagement
Connect-IPPSSession
Next, you'll need to
- Identify the case and search.
- Load the email addresses from the text file.
- Use the
Set-ComplianceSearch
cmdlet to update the search's data sources (email addresses in this case). -
Set-ComplianceSearch
's–ExchangeLocation
parameter takes a string array of user identities (email addresses, usernames, etc.).
Note that there’s a 10,000 item limit per search, but fortunately that’s not a concern in your case (you have ~1900). In addition, the update overwrites the ExchangeLocation
list—so each time you call Set-ComplianceSearch
, it replaces the previous values unless you maintain a growing list in the script.
# Define variables
$caseName = "Test Case"
$searchName = "Test Case Search Name"
$addressFile = "C:\testcaseaddressfile.txt"
# Read all addresses from file
$emailAddresses = Get-Content -Path $addressFile
# Convert to array if not already
$emailArray = $emailAddresses | ForEach-Object { $_.Trim() }
# Update the compliance search
Set-ComplianceSearch -Identity $searchName -Case $caseName -ExchangeLocation $emailArray
If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.
hth
Marcin