Quantcast
Channel: Exchange Server 2013 - Administration, Monitoring, and Performance 论坛
Viewing all articles
Browse latest Browse all 8719

Delete emails by retrieving the data (subject line) from CSV file

$
0
0

Hi,

I have a CSV file which has the data as below:

recipient,subject
administrator@test.com,test4
abc@test.com,test5

My requirement is to write a one liner or script so that it gets the recipient address and search for messages with that corresponding subject line and delete them.

I have tried the below one-liners but the search results are null:(resultant item count says zero)

import-csv .\test.csv | ForEach-Object {search-mailbox $_.recipient -searchquery 'subject: "$_.subject"' -deletecontent}

import-csv .\test.csv | ForEach-Object {search-mailbox $_.recipient -searchquery 'subject: $_.subject' -deletecontent}

Result:

ResultItemsCount : 0
ResultItemsSize  : 0 B (0 bytes)

I have also tried in the below way (by importing the csv to a variable D and then the below query)

ForEach-Object {Search-Mailbox $d.recipient -SearchQuery 'subject: $d.subject' -DeleteContent}

But the results are same as above.

But when I run the query below, it gives me expected result:

Search-Mailbox abc -SearchQuery 'subject: test5' -DeleteContent

ResultItemsCount : 1
ResultItemsSize  : 8.563 KB (8,768 bytes)

Any one has ideas on how to get this job done by taking the data from CSV file ?


Viewing all articles
Browse latest Browse all 8719

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>