artofscripting

test3

May 16th, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  param (
  3.     [string]$directory = "C:\logs"
  4.  
  5.  )
  6.  
  7.  Function Set-EventlogPath ([string]$Computername=$env:COMPUTERNAME,[string]$NewLogDir,[string]$LogName)
  8. {
  9.     [reflection.assembly]::loadwithpartialname("System.Diagnostics.Eventing.Reader")
  10.     $Eventlogsession = New-Object System.Diagnostics.Eventing.Reader.EventLogSession -ArgumentList $Computername
  11.    
  12.         $Eventlogconfig = New-Object System.Diagnostics.Eventing.Reader.EventLogConfiguration -ArgumentList $LogName,$Eventlogsession
  13.         $Logfilepath = $Eventlogconfig.LogFilePath
  14.         $Logfile = Split-Path $Logfilepath -Leaf
  15.         $NewLogFilePath = "$NewLogDir\$Logfile"
  16.  
  17.          Write-Host -ForegroundColor Yellow $LogName,$Logfilepath,$Eventlogconfig.LogType
  18.          
  19.         if (($Eventlogconfig.LogType -eq "Debug" -or$Eventlogconfig.LogType -eq " Analytical") -and $Eventlogconfig.IsEnabled)
  20.         {
  21.             $Eventlogconfig.IsEnabled = $false
  22.             $Eventlogconfig.SaveChanges()  
  23.  
  24.             $Eventlogconfig.LogFilePath = $NewLogFilePath
  25.             $Eventlogconfig.SaveChanges()  
  26.  
  27.        
  28.               $Eventlogconfig.IsEnabled = $true
  29.               $Eventlogconfig.SaveChanges()
  30.  
  31.             }
  32.         else
  33.         {
  34.             $Eventlogconfig.LogFilePath = $NewLogFilePath
  35.                $Eventlogconfig.SaveChanges()
  36.  
  37.  
  38.             }
  39.          
  40.     }
  41.  
  42. If(!(test-path $directory))
  43. {
  44.       New-Item -ItemType Directory -Force -Path $directory
  45. }
  46.  
  47.  
  48. Set-EventlogPath -Computername localhost -NewLogDir $directory -LogName Security
  49. $limitParam = @{
  50.   Maximumsize = 200MB
  51.   logname = "Security"
  52.   RetentionDays = 90
  53.   OverflowAction = "OverwriteOlder"
  54. }
  55.  
  56. Limit-EventLog @limitParam
  57.  
  58.  
  59. Get-Eventlog -list | where {$_.Log -eq $limitparam.logname}
Add Comment
Please, Sign In to add comment