ConvertTo-Html in Powershell

# This PowerShell script gives information about the events of ERROR,CRITICAL and WARNING, and this provides today data alone.
 
 
cls
$Computername=$env:COMPUTERNAME
 
$a = get-date
$month =$a.tostring("MM")
$day = $a.tostring("dd")
$year = $a.tostring("yyyy")
$OutFile="D:\ServerList\"+$Computername+"_Error_Warning_Critical.html"
$csname=$Computername+"_Warning_Error_Critical"
Get-WinEvent `
-LogName Application,System |
Select-Object @{Name="Service";expression={$_.ProviderName}},
TimeCreated,
Id,@{Name="Level";expression={$_.LevelDisplayName}},Message |
Where-Object {(($_.Level -eq 'warning') -or ($_.Level -eq 'Error') -or ($_.Level -eq 'Critical')) -and ($_.Timecreated -like "*$month/$day/$year*")} |
Sort-Object Level |ConvertTo-Html > $OutFile
 
#Sending mail
Send-MailMessage `
-To 'tomailidhere' `
-Subject $csname `
-From 'FRomMailIDhere' `
-SmtpServer 'SMTPServerIPornamehere' `
-Attachments $OutFile
 
 

Comments

Bhanu Sree said…
The information which you have provided is very good. It is very useful who is looking for
SQL Azure Online Training
Azure SQL Training
SQL Azure Training

Popular posts from this blog

System.Data.SqlClient.SqlException (0x80131904): Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out

Pre login Handshake or Connection Timeout Period

Transparent Data Encryption(TDE) with Master Key and Certificate in SQL Server