Hi,
can you help change this script around a little bit? :-)
1. I'd need to the line: " [Void]($_.Message -Match "(https?://)?([A-Za-z0-9\-]{2,64}\.)+[A-Za-z]{2,6}") " to include email addresses as well as URL's (it does URL's beautifully)
2. I need to change this line as well " @{n='Number';e={ $WhiteListEntry.PNumbers }} " as I would need in to have all the non-white listed phone numbers in $Message displayed under the 'Number' column.
full code blew.
make sense?
Thanks in advance for all your help.
Jason.
CSV's pasted below..
#sms_rcv.csv
Date,Time,Sender,Recipient,Status,Message,Details
9/22/2009,"1:09:21 PM","+123456789000","user@domain.com","Success","Really cool +9725568432144 stuff","Success. SMS received."
9/22/2009,"1:09:30 PM","+123456789000","user@domain.com","Success","test +298989784511 jim@janis-jop.com","Success. SMS received."
9/22/2009,"1:09:38 PM","+123456789000","user@domain.com","Success","test www.cnn.com robin hood is good","Success. SMS received."
9/22/2009,"1:09:47 PM","+123456789000","user@domain.com","Success","test +975885654321 www.art.com is there something nice to eat","Success. SMS received."
#white_list.csv
Pnumbers
972556843214,
123456789000,
975885654321,
#copy the file Over
gc "C:\Program Files (x86)\sms\sms_recv.log" | where {$_ -ne ""} > sms_rcv.csv
# Convert from UTC to this time zone (offset in hours)
$TimeZoneOffset = -5
# Load the last weeks messages from file
$FileName = "E:\count\sms\sms_rcv.csv"
$Messages = Import-CSV $FileName | Select-Object `
@{n='DateTime';e={ ([DateTime]"$($_.Date) $($_.Time)").AddHours($TimeZoneOffset) }}, `
Sender, Recipient, Status, Message, Details | `
Where-Object { $_.DateTime -gt (Get-Date).Date.AddDays(-7) }
# White List Filtering
$WhiteList = Import-CSV "white_list.csv"
# Select all fields from $Messages and add a Known field.
# Set Confirmed if phone number followed by a space exists in white list
# digits before the phone number are ignored (such as area / country codes)
$Messages = $Messages | %{
$Message = $_.Message
$WhiteListEntry = $WhiteList | ?{ $Message -Match "$($_.PNumbers)\s" }
$_ | Select-Object *, `
@{n='Known';e={ If ($WhiteListEntry) { "White-listed" } else { "Not White-listed" } }}, `
@{n='Number';e={ $WhiteListEntry.PNumbers }}
}
# Add the URL column
$Messages = $Messages | Select-Object *, `
@{n='URL';e={
$Matches = $Null
[Void]($_.Message -Match "(https?://)?([A-Za-z0-9\-]{2,64}\.)+[A-Za-z]{2,6}")
If ($Matches) { $Matches[0] }
}}
# Generate the report
$Subject = "Last week there were $($Messages.Count) Items"
# The image at this path will be embedded into the message
$ImagePath = "E:\count\sms\logo1.jpg"
# Create the CSS Header
$Header = "<style>table {font-size: 10pt; font-family: calibri;}
body {background-color:black;}
table {align: cernter; border-width: 1px;border-style: solid; border-color: black; border-collapse: collapse;}
th {font-size:1em; border-width: 1px;padding: 2px; border-style: solid; border-color: white; background-color: pink}
td {font-size:0.8em; border-width: 1px;padding: 2px; border-style: solid; border-color: white; background-color: green}
</style>"
# Body (inserted above the HTML table)
$Body = "<h2><img src=cid:Logo />SMS Item Detailed Report ($Subject).</h2>"
# Smtp details
$SmtpServer = "localhost"
$From = "sender@domain"
$To = "rcpt@domain.com"
# Generate the full message body from the report
$MessageBody = $Messages | ConvertTo-Html -Head $Header -Body $Body
# Create the mail message
$MailMessage = New-Object Net.Mail.MailMessage($From, $To)
$MailMessage.Subject = $Subject
$MailMessage.IsBodyHtml = $True
# Create a linked resource to store the image
$LinkedResource = New-Object Net.Mail.LinkedResource($ImagePath, "image/jpeg")
$LinkedResource.ContentId = "Logo";
# Create an Html view and add the linked resource
$HtmlView = [Net.Mail.AlternateView]::CreateAlternateViewFromString($MessageBody, "text/html")
$HtmlView.LinkedResources.Add($LinkedResource)
# Add the view to the message
$MailMessage.AlternateViews.Add($HtmlView)
# Send the mail
(New-Object Net.Mail.SmtpClient($SMTPServer)).Send($MailMessage)
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
Select allOpen in new window
by: LearnctxPosted on 2009-10-19 at 17:16:15ID: 25610045
Not my regex, but one from here.
Select allOpen in new window