1 | powershell.exe -noexit -nologo -WindowStyle Hidden -ExecutionPolicy unrestricted -command "& 'C:\powershellscript.ps1'" |
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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | <################################################################## ## Check Trasnsport Servers NDR emails in queues and report to ## ## administrators via eamil ## ## ## ## Modify values under VARS section for email settings ## ## ## ###################################################################> #Add Exchange Tools Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction SilentlyContinue; ## START VARS $emails = @( ) $mailSubject = "Daily NDR Report for DOMAIN" $mailServer = "mail.domain.com" ## FUNCTIONS function msg_get_queue() { $mQ = @() $mQ = Get-ExchangeServer | ? {$_.isHubTransportServer -eq $true} | get-queue | ? {$_.MessageCount -gt 0} return $mQ } function msg_get_msgFromQ($i) { $mFQ = @() foreach ($x in $i) { $mFQ += ($x | Get-Message) } return $mFQ } function msg_get_details($i) { $mQD = @() foreach ($svr in (Get-ExchangeServer | ? {$_.isHubTransportServer -eq $true})) { $mQD += Get-MessageTrackingLog -MessageId $i -Server $svr.Name | ? {$_.EventID -eq "RECEIVE"} } return $mQD } ## FUNCTION TO GET Q AND BUILD EMAIL function msg_get_NDR_details() { $html = " <meta http-equiv="" content="" charset="us-asciiamp;"amp;"" /> <meta name="Generator" content="" /></pre> <style><!-- /* Font Definitions */@font-face {font-family: ""Tahoma"";panose-1: 0 0 0 0 0 0 0 0 0 0;}/* Style Definitions */p.MsoNormal, li.MsoNormal, div.MsoNormal {margin-top: 0in;margin-right: 0in;margin-bottom: 10.0pt;margin-left: 0in;line-height: 115%;font-size: 11.0pt;font-family: ""Tahoma"";}a:link, span.MsoHyperlink {mso-style-priority: 99;color: #001C54;text-decoration: underline;}a:visited, span.MsoHyperlinkFollowed {mso-style-priority: 99;color: #DDEBED;text-decoration: underline;}span.EmailStyle17 {mso-style-type: personal-compose;font-family: ""Tahoma"";color: windowtext;}.MsoChpDefault {mso-style-type: export-only;font-family: ""Tahoma"";}@page WordSection1 {size: 8.5in 11.0in;margin: 1.0in 1.0in 1.0in 1.0in;}div.WordSection1 {page: WordSection1;} --></style> <pre> <!--[if gte mso 9]> <xml> <o:shapedefaults v:ext=""edit"" spidmax=""1026"" /> </xml> <![endif]--> <!--[if gte mso 9]> <xml> <o:shapelayout v:ext=""edit""> <o:idmap v:ext=""edit"" data=""1"" /> </o:shapelayout> </xml> <![endif]--> </pre> <div class="WordSection1">" foreach ($subQ in (msg_get_queue)) { foreach ($subMsg in $subQ) { $html += " <table style="width: 98.0%; border-collapse: collapse; border: none;" width="" border="1" cellspacing="0" cellpadding="0"> <tbody> <tr> <td style="border: solid white 1.0pt; border-bottom: solid white 3.0pt; background: #ECECE5; padding: 0in 5.4pt 0in 5.4pt;" valign="top"> <b> <span style="color: #404040; mso-style-textfill-fill-color: #404040; mso-style-textfill-fill-alpha: 100.0%;"> $($subMsg.NextHopDomain)<br/ > </span> </b> <span style="color: #404040; mso-style-textfill-fill-color: #404040; mso-style-textfill-fill-alpha: 100.0%;"> $($subMsg.Status) due to $($subMsg.DeliveryType), will try again on $($subMsg.NextRetryTime) Last Error: $($subMsg.LastError) </span></td> </tr> <tr> <td>" foreach ( $subDetails in (msg_get_msgFromQ($subMsg)) ) { $rows = msg_get_details($subDetails.InternetMessageId) foreach ($row in $rows) { $html += " " } } $html += " <table style="width: 99.0%; border-collapse: collapse; border: none;" width="" border="1" cellspacing="0" cellpadding="0" align=""> <tbody> <tr> <td valign=""> <b> <span style="color: #404040; mso-style-textfill-fill-color: #404040; mso-style-textfill-fill-alpha: 100.0%;">EventID</span> </b></td> <td valign=""> <b> <span style="color: #404040; mso-style-textfill-fill-color: #404040; mso-style-textfill-fill-alpha: 100.0%;">Source</span> </b></td> <td valign=""> <b> <span style="color: #404040; mso-style-textfill-fill-color: #404040; mso-style-textfill-fill-alpha: 100.0%;">Sender</span> </b></td> <td valign=""> <b> <span style="color: #404040; mso-style-textfill-fill-color: #404040; mso-style-textfill-fill-alpha: 100.0%;">Recipients</span> </b></td> <td valign=""> <b> <span style="color: #404040; mso-style-textfill-fill-color: #404040; mso-style-textfill-fill-alpha: 100.0%;">MessageSubject</span> </b></td> <td valign=""> <b> <span style="color: #404040; mso-style-textfill-fill-color: #404040; mso-style-textfill-fill-alpha: 100.0%;">TotalBytes</span> </b></td> <td valign=""> <b> <span style="color: #404040; mso-style-textfill-fill-color: #404040; mso-style-textfill-fill-alpha: 100.0%;">ServerHostname</span> </b></td> </tr> <tr> <td style="border-top: none; border-left: none; border-bottom: solid white 1.0pt; border-right: solid white 1.0pt; background: #FAFAF8; padding: 0in 5.4pt 0in 5.4pt;" align="" valign=""> $($row.EventID)</td> <td style="border-top: none; border-left: none; border-bottom: solid white 1.0pt; border-right: solid white 1.0pt; background: #FAFAF8; padding: 0in 5.4pt 0in 5.4pt;" align="" valign=""> $($row.Source)</td> <td style="border-top: none; border-left: none; border-bottom: solid white 1.0pt; border-right: solid white 1.0pt; background: #FAFAF8; padding: 0in 5.4pt 0in 5.4pt;" align="" valign=""> $($row.Sender)</td> <td style="border-top: none; border-left: none; border-bottom: solid white 1.0pt; border-right: solid white 1.0pt; background: #FAFAF8; padding: 0in 5.4pt 0in 5.4pt;" align="" valign=""> $($row.Recipients)</td> <td style="border-top: none; border-left: none; border-bottom: solid white 1.0pt; border-right: solid white 1.0pt; background: #FAFAF8; padding: 0in 5.4pt 0in 5.4pt;" align="" valign=""> $($row.MessageSubject)</td> <td style="border-top: none; border-left: none; border-bottom: solid white 1.0pt; border-right: solid white 1.0pt; background: #FAFAF8; padding: 0in 5.4pt 0in 5.4pt;" align="" valign=""> $($row.TotalBytes)</td> <td style="border-top: none; border-left: none; border-bottom: solid white 1.0pt; border-right: solid white 1.0pt; background: #FAFAF8; padding: 0in 5.4pt 0in 5.4pt;" align="" valign=""> $($row.ServerHostname)</td> </tr> </tbody> </table> </td> </tr> <tr> <td style="border: solid white 1.0pt; border-bottom: solid white 3.0pt; background: #ECECE5; padding: 0in 5.4pt 0in 5.4pt;" valign="top"> <b> <span style="color: #404040; mso-style-textfill-fill-color: #404040; mso-style-textfill-fill-alpha: 100.0%;"> Total Messages in this Queue: $($subMsg.MessageCount) </span> </b></td> </tr> </tbody> </table> " } } $html += " </div> <pre> " return $html } #SEND EMAIL Send-MailMessage -SmtpServer $mailServer -To $emails -From $fromAddress -subject $mailSubject -bodyAsHtml (msg_get_NDR_details) |
When I run the script I get this error
Unexpected token ‘function’ in expression or statement.
At C:\Data\Scripts\PowerShell\SendFileAlert\SendFileAlert.ps1:19 char:12
+ 10 function <<<< sendMail($s) {
+ CategoryInfo : ParserError: (function:String) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken
Can you help?
Thanks!
Sure, can you post or send me your PS1 file?