-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRemove-EventSource.ps1
22 lines (21 loc) · 1.07 KB
/
Remove-EventSource.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$subscriptions = Get-ChildItem -Path HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\EventCollector\Subscriptions | select Name
foreach ($sub in $subscriptions){
$sub = $sub."Name".split('\')[7]
$eventsources = Get-childItem -Path HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\EventCollector\Subscriptions\$sub\EventSources | select name
foreach ($source in $eventsources){
$source = ($source."Name" -split '\\',2)[1]
$regkey = Get-ItemProperty -Path HKLM:$source
foreach ($reg in $regkey){
$LastHeartBeatTime = $reg.LastHeartBeatTime
$date = [DateTime]::FromFileTime($LastHeartBeatTime)
$today = Get-Date
$timediff = New-Timespan -Start $date -End $today
if ($timediff.Days -gt 30){
$wefclient = $reg.PSChildName
write-host "$wefclient has not checked in 30 days."
write-host "Removing $wefclient from $sub subscription.`n"
Remove-Item $reg.PSPath -Force -Recurse
}
}
}
}