-
Notifications
You must be signed in to change notification settings - Fork 1
/
Set-Eventlogpath-Sivakarthi.ps1
32 lines (27 loc) · 1.4 KB
/
Set-Eventlogpath-Sivakarthi.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#usage : Set-Eventlogpath -Computername <Computername>
Function Set-EventlogPath ([string]$Computername=$env:COMPUTERNAME,[string]$NewLogDir)
{
[reflection.assembly]::loadwithpartialname("System.Diagnostics.Eventing.Reader")
$Eventlogsession = New-Object System.Diagnostics.Eventing.Reader.EventLogSession -ArgumentList $Computername
Foreach($LogName in $Eventlogsession.GetLogNames()) {
$Eventlogconfig = New-Object System.Diagnostics.Eventing.Reader.EventLogConfiguration -ArgumentList $LogName,$Eventlogsession
$Logfilepath = $Eventlogconfig.LogFilePath
$Logfile = Split-Path $Logfilepath -Leaf
$NewLogFilePath = "$NewLogDir\$Logfile"
Write-Host -ForegroundColor Yellow $LogName,$Logfilepath,$Eventlogconfig.LogType
if (($Eventlogconfig.LogType -eq "Debug" -or$Eventlogconfig.LogType -eq " Analytical") -and $Eventlogconfig.IsEnabled)
{
$Eventlogconfig.IsEnabled = $false
$Eventlogconfig.SaveChanges()
$Eventlogconfig.LogFilePath = $NewLogFilePath
$Eventlogconfig.SaveChanges()
$Eventlogconfig.IsEnabled = $true
$Eventlogconfig.SaveChanges()
}
else
{
$Eventlogconfig.LogFilePath = $NewLogFilePath
$Eventlogconfig.SaveChanges()
}
}
}