Solved

Powershell Help

Posted on 2016-09-28
2
33 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 70

Accepted Solution

by:
Qlemo earned 500 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

752 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