Avatar of RMDOps
RMDOps
 asked on

Powershell Help

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

}
PowershellActive Directory

Avatar of undefined
Last Comment
Qlemo

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Qlemo

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck