Could you please help me!?
This is what I'm trying to achieve with PowerShell - export emails to CSV file from particular mailbox with needed data (Subject, FromDisplayName, SubmittedDateTime, MessageTrackingReportId). So I made it using following four strings:
$msg = Search-MessageTrackingReport -Identity MyMailBox -BypassDelegateChecking
#get relevant info from that mailbox and save it to CSV file
$msg | %{ Get-MessageTrackingReport -Identity $_.MessageTrackingReportId -BypassDelegateChecking } | Select Subject, FromDisplayName, SubmittedDateTime, MessageTrackingReportId | Export-CSV C:\MyFile.csv -NoTypeInformation
#import CSV file and get rid of dublicates and select only needed columns
$temp = Import-CSV C:\MyFile.csv | sort MessageTrackingReportId -Unique | Select Subject, FromDisplayName, SubmittedDateTime
#export CSV file
$file = $temp | Export-CSV C:\MyFile.csv -NoTypeInformation
But the problem I'm facing is that Subject of email may look like this:
** FAN-CRITICAL Service Alert: LTC-SW-NEX01/fan-status is OK ** (24x7 OOH Alerts)
or
** SM-CRITICAL Service Alert: PRDDC1FAS001/snapmirror-lagtime is CRITICAL ** (24x7 OOH Alerts)
or
** RECOVERY Service Alert: PRDDC1ADS001/CPU Load is WARNING ** (24x7 OOH Alerts)
or
... (Something in similar format)
So I need to split this string and replace Subject column with those four new columns in my CSV file:
AlertType which is -
FAN-CRITICAL Service AlertorSM-CRITICAL Service AlertorRECOVERY Service Alertor...MachineName which is -
LTC-SW-NEX01orPRDDC1FAS001orPRDDC1ADS001or...AlertName which is -
fan-statusorsnapmirror-lagtimeorCPU Loador...Status which is -
OKorCRITICALorWARNINGor...
So in the end of the day my CSV file should have these following columns:
- AlertType
- MachineName
- AlertName
- Status
- FromDisplayName
- SubmittedDateTime
- MessageTrackingReportId
I know that I need to use RegEx but I don't have any experience working with it, so could anyone please help me, how can I combine PowerShell and RegEx to achieve my goals.
Thanks in advance!