title: PowerShell script to send me email alerts of Event Viewer errors/warnings/failures
body: <p>I am trying to edit the script below to utilize the task scheduler send me an email notification every time an error/warning/failure is logged in our servers Event Viewer.</p>
  <p>Important info:</p>
  <ul>
  <li>I am brand new to PowerShell</li>
  <li>The from email and to email are both apart of my company's outlook exchange server</li>
  <li>I need this script to pull events from the &quot;Windows&quot; log folder in Event Viewer</li>
  <li>I also believe this script requires a module installation, which I am struggling to figure out how to do</li>
  <li>I need to know what to edit (I believe in the parameters) to make to fit my specific use case</li>
  </ul>
  <p>Thanks in advance for any help at all. Here is the script from <a href="https://github.com/blachniet/blachniet-psutils/blob/master/Send-EventEntryEmail.psm1" rel="nofollow noreferrer">https://github.com/blachniet/blachniet-psutils/blob/master/Send-EventEntryEmail.psm1</a> :</p>
  <pre><code>Import-Module $PSScriptRoot\Send-EventEntryEmail.psm1
  
  Function Send-EventEntryEmail {
  
  [CmdletBinding()]
      param(
          [Parameter()]
          [string] $LogName = &quot;System&quot;&quot;Application&quot;&quot;Security,
      
          [Parameter(Mandatory=$true)]
          [string] $Source,
      
          [Parameter()]
          [int] $Newest = 5,
  
          [Parameter()]
          [string[]] $EntryType = &quot;Error&quot;&quot;Warning&quot;&quot;Failure&quot;,
      
          [Parameter(Mandatory=$true)]
          [string] $SmtpUser = &quot;helpdesk@mydomain.com&quot;,
      
          [Parameter(Mandatory=$true)]
          [string] $SmtpPassword = &quot;passwordexample&quot;,
      
          [Parameter()]
          [int] $SmtpPort = 587,
      
          [Parameter()]
          [string] $SmtpServer = &quot;smtp.mail.outlook.com&quot;,
      
          [Parameter(Mandatory=$true)]
          [string] $MailFrom = &quot;helpdesk@mydomain.com&quot;,
      
          [Parameter(Mandatory=$true)]
          [string] $MailTo = &quot;myemail@mydomain.com,
      
          [Parameter()]
          [string] $Subject = &quot;EventLogAlert&quot;,
  
      )
  
      # Get the event entries.
      $eventEntries = Get-EventLog -LogName $LogName -Source $Source -Newest $Newest -EntryType $EntryType
  
      # Create a table row for each entry.
      $rows = &quot;&quot;
      foreach ($eventEntry in $eventEntries){
          $rows += @&quot;
          &lt;tr&gt;
              &lt;td style=&quot;text-align: center; padding: 5px;&quot;&gt;$($eventEntry.TimeGenerated)&lt;/td&gt;
              &lt;td style=&quot;text-align: center; padding: 5px;&quot;&gt;$($eventEntry.EntryType)&lt;/td&gt;
              &lt;td style=&quot;padding: 5px;&quot;&gt;$($eventEntry.Message)&lt;/td&gt;
          &lt;/tr&gt;
  &quot;@
      }
  
      # Create the email.
      $email = New-Object System.Net.Mail.MailMessage( $MailFrom , $MailTo )
      $email.Subject = $Subject
      $email.IsBodyHtml = $true
      $email.Body = @&quot;
      &lt;table style=&quot;width:100%;border&quot;&gt;
          &lt;tr&gt;
              &lt;th style=&quot;text-align: center; padding: 5px;&quot;&gt;Time&lt;/th&gt;
              &lt;th style=&quot;text-align: center; padding: 5px;&quot;&gt;Type&lt;/th&gt;
              &lt;th style=&quot;text-align: center; padding: 5px;&quot;&gt;Message&lt;/th&gt;
          &lt;/tr&gt;
      
      $rows
      &lt;/table&gt;
  &quot;@
  
      # Send the email.
      $SMTPClient=New-Object System.Net.Mail.SmtpClient( $SmtpServer , $SmtpPort )
      $SMTPClient.EnableSsl=$true
      $SMTPClient.Credentials=New-Object System.Net.NetworkCredential( $SmtpUser , $SmtpPassword );
      $SMTPClient.Send( $email )
  }
  
  Export-ModuleMember Send-EventEntryEmail
  </code></pre>
  <p>Below are the errors I get in ISE when I run this current script:</p>
  <pre><code>At line:17 char:34
  +         [string[]] $EntryType = &quot;Error&quot;&quot;Warning&quot;&quot;Failure&quot;,
  +                                  ~
  Missing ')' in function parameter list.
  At line:35 char:49
  +         [string] $MailTo = &quot;myemail@mydomain.com,
  +                                                 ~
  Missing argument in parameter list.
  At line:37 char:20
  +         [Parameter()]
  +                    ~
  An expression was expected after '('.
  At line:38 char:45
  +         [string] $Subject = &quot;EventLogAlert&quot;,
  +                                             ~
  Missing expression after ','.
  At line:3 char:31
  + Function Send-EventEntryEmail {
  +                               ~
  Missing closing '}' in statement block or type definition.
  At line:40 char:5
  +     )
  +     ~
  Unexpected token ')' in expression or statement.
  At line:78 char:1
  + }
  + ~
  Unexpected token '}' in expression or statement.
      + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
      + FullyQualifiedErrorId : MissingEndParenthesisInFunctionParameterList
  </code></pre>