>@---------------------------@<..." />

Logging Windows Event error into text file

Print
$Type = "Error"
$LogFile = "c:\LogFile.txt"
$NewestLogID = 500

Out-File $LogFile

Out-File $LogFile -append -inputobject "      >>@---------------------------@< <"
Out-File $LogFile -append -inputobject "      >>@---   System EventLog   ---@< <"
Out-File $LogFile -append -inputobject "      >>@---------------------------@< <"

$Log = "System"
Get-EventLog -computername MyComputer -logname $Log -newest $NewestLogID | ForEach-Object {
  If ($_.EntryType -eq $Type) {
   Out-File $LogFile -append -inputobject $_.timewritten
   Out-File $LogFile -append -inputobject $_.Source
   Out-File $LogFile -append -inputobject $_.Message
  }
}

Out-File $LogFile -append -inputobject " "
Out-File $LogFile -append -inputobject "      >>@--------------------------------@< <"
Out-File $LogFile -append -inputobject "      >>@---   Application EventLog   ---@< <"
Out-File $LogFile -append -inputobject "      >>@--------------------------------@< <"

$Log = "Application"
Get-EventLog -computername MyComputer -logname $Log -newest $NewestLogID | ForEach-Object {
  If ($_.EntryType -eq $Type) {
   Out-File $LogFile -append -inputobject $_.timewritten
   Out-File $LogFile -append -inputobject $_.Source
   Out-File $LogFile -append -inputobject $_.Message
  }
}

 

This website uses cookies to ensure you get the best experience on our website.