>@[email protected]<..." />

Italian (IT)

Logging Windows Event error into text file

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

Out-File $LogFile

Out-File $LogFile -append -inputobject "      >>@[email protected]< <"
Out-File $LogFile -append -inputobject "      >>@---   System EventLog   [email protected]< <"
Out-File $LogFile -append -inputobject "      >>@[email protected]< <"

$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 "      >>@[email protected]< <"
Out-File $LogFile -append -inputobject "      >>@---   Application EventLog   [email protected]< <"
Out-File $LogFile -append -inputobject "      >>@[email protected]< <"

$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
  }
}

 


© 2017 Bruno Tessaro. My life in the web. All right reserved.

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