Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Powershell Help

Posted on 2016-09-28
2
Medium Priority
?
42 Views
Last Modified: 2016-10-18
Hi

The purpose of this script is to scan every email from the past 24 hours that has hit email xxxx@domain.com
The subject has a username in pond or hash (#xxxx#) for example. RE: account notification for #charlesb# expiring
I have found a logic to extract the text between the pond/hash, but unfortunately it only does it for the first result and does not continue to the next. Please advise

##date minus 24hours
$startdate=("{0:dd/MM/yyyy hh:mm:ss }" -f (get-date).AddDays(-1))
##todays date
$enddate=get-date -Format G


Get-TransportServer -Identity 'hubserv' |Get-Messagetrackinglog -Recipients: xxxx@domain.com -EventID “RECEIVE” -Start ”$startdate” -End ”$enddate” |select MessageSubject, Sender | export-csv C:\Charlie\email.csv -NoTypeInformation

$messagesubjects=import-csv C:\Charlie\email.csv | Out-String

foreach($messagesubject in $messagesubjects) {

$start= $messagesubject.indexof("#") +1

$end= $messagesubject.indexof("#", $start)
$length =$end - $start
$messagesubjects.substring($start, $length) | out-file C:\Charlie\usertest.txt -Append

}
0
Comment
Question by:RMDOps
2 Comments
 
LVL 71

Accepted Solution

by:
Qlemo earned 2000 total points (awarded by participants)
ID: 41821196
In your last line, use $messagesubject instead of $messagesubjects.
Of course you are aware that the steps you take to get the result are long-winded and cumbersome?
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here's a look at newsworthy articles and community happenings during the last month.
Let's recap what we learned from yesterday's Skyport Systems webinar.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question