Advertisement
Jabba87

Custom Viewconfig

Feb 11th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function writeFile([string] $path, [string] $name){
  2.     If(!(test-path $path))
  3.     {
  4.         New-Item -ItemType Directory -Force -Path $path | Out-Null
  5.     }
  6.     $fileCount=@(Get-ChildItem $path -File).Count
  7. '<ViewerConfig>
  8.  <Name>'+$name+'</Name>
  9.  <ResultsConfig>
  10.    <Columns>
  11.      <Column Name="Ebene" Type="System.String" Path="Event/System/Level" Visible="">140</Column>
  12.      <Column Name="Schlüsselwörter" Type="System.String" Path="Event/System/Keywords">200</Column>
  13.      <Column Name="Datum und Uhrzeit" Type="System.DateTime" Path="Event/System/TimeCreated/@SystemTime" Visible="">145</Column>
  14.      <Column Name="Quelle" Type="System.String" Path="Event/System/Provider/@Name" Visible="">550</Column>
  15.      <Column Name="Ereignis-ID" Type="System.UInt32" Path="Event/System/EventID" Visible="">200</Column>
  16.      <Column Name="Aufgabenkategorie" Type="System.String" Path="Event/System/Task" Visible="">250</Column>
  17.      <Column Name="Benutzer" Type="System.String" Path="Event/System/Security/@UserID">50</Column>
  18.      <Column Name="Vorgangscode" Type="System.String" Path="Event/System/Opcode">110</Column>
  19.      <Column Name="Protokoll" Type="System.String" Path="Event/System/Channel">100</Column>
  20.      <Column Name="Computer" Type="System.String" Path="Event/System/Computer" Visible="">170</Column>
  21.      <Column Name="Prozess-ID" Type="System.UInt32" Path="Event/System/Execution/@ProcessID">70</Column>
  22.      <Column Name="Thread-ID" Type="System.UInt32" Path="Event/System/Execution/@ThreadID">70</Column>
  23.      <Column Name="Prozessor-ID" Type="System.UInt32" Path="Event/System/Execution/@ProcessorID">90</Column>
  24.      <Column Name="Sitzungs-ID" Type="System.UInt32" Path="Event/System/Execution/@SessionID">70</Column>
  25.      <Column Name="Kernel-Zeit" Type="System.UInt32" Path="Event/System/Execution/@KernelTime">80</Column>
  26.      <Column Name="Benutzerzeit" Type="System.UInt32" Path="Event/System/Execution/@UserTime">70</Column>
  27.      <Column Name="Prozessor-Zeit" Type="System.UInt32" Path="Event/System/Execution/@ProcessorTime">100</Column>
  28.      <Column Name="Korrelations-ID" Type="System.Guid" Path="Event/System/Correlation/@ActivityID">85</Column>
  29.      <Column Name="Relative Korrelations-ID" Type="System.Guid" Path="Event/System/Correlation/@RelatedActivityID">140</Column>
  30.      <Column Name="Ereignisquellname" Type="System.String" Path="Event/System/Provider/@EventSourceName">140</Column>
  31.    </Columns>
  32.  </ResultsConfig>
  33. </ViewerConfig>' | Out-File "$path\Channel_$fileCount.xml"
  34. }
  35. function localize($text){
  36. $localeTable = @{
  37.         "Operational" = "Betriebsbereit"
  38.         "HardwareEvents" = "Hardware-Ereignisse"
  39.         "Security" = "Sicherheit"
  40.         "Application" = "Anwendung"
  41.         "Key Management Service" = "Schlüsselverwaltungsdienst"
  42.         "ForwardedEvents" = "Weitergeleitete Ereignisse"
  43.         "Setup" = "Installation"
  44.         "OAlerts" = "Microsoft Office Alerts"
  45.         "Windows Networking Vpn Plugin Platform" = "Microsoft\Windows\Vpn Plugin Platform"
  46.         "Microsoft\Windows\WDAG-PolicyEvaluator-CSP" = "CSP\Anbieter für WDAG\Richtlinienauswerter"
  47.         "Microsoft\Windows\WDAG-PolicyEvaluator-GP" =  "GP\Anbieter für WDAG\Richtlinienauswerter"
  48.         "Admin" = "Administrator"      
  49. }
  50.     if($retVal=$localeTable[$text]){
  51.         return $retVal
  52.     }else{
  53.         return $text
  54.     }
  55. }
  56.  
  57. $path = "$env:ProgramData\Microsoft\Event Viewer"
  58. $windows = @("Application", "Security", "System", "ForwardedEvents", "Setup")
  59. $builtin = $path+"\Windows-Protokolle"
  60. $app = $path+"\Anwendungs- und Dienstprotokolle"
  61.  
  62. Remove-Item -Recurse -Force $app"\*"
  63. Remove-Item -Recurse -Force $builtin"\*"
  64.  
  65. Get-WinEvent -ListLog * | % {
  66.     if($windows.Contains($_.LogName)){
  67.         writeFile $builtin (localize $_.LogName)
  68.     }else{
  69.         $components = $_.Logname.Split("/")
  70.         if($components.Count -gt 1) {
  71.             $name = $components[1]
  72.             $components= $components[0].Split("-")
  73.         }else{
  74.             [System.Collections.ArrayList]$components= $components[0].Split("-")
  75.             $name = $components[-1]
  76.             $components.RemoveAt($components.Count-1)
  77.         }
  78.         if($components.Count -gt 2){
  79.             $components = $components[0..1] +($components[2..($components.Count-1)] -join "-")
  80.         }
  81.         $path = localize ($components -join "\")
  82.         WriteFile "$app\$path" (localize $name)
  83.         #Operational ist manchmal übersetzt und manchmal nicht, deswegen beides schreiben
  84.         if($name -eq "Operational" -or $name -eq "Admin"){
  85.             writeFile "$app\$path" $name
  86.         }
  87.     }    
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement