Advertisement
Old-Lost

Get-EventLogSource

Jun 8th, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Get-EventLogSource {
  2.     param ([Parameter(Mandatory, Position = 0)][SupportsWildcards()][string]$Name,
  3.         [Parameter(Position = 1)][string]$LogName)
  4.     $x = Get-ChildItem HKLM:\SYSTEM\CurrentControlSet\Services\EventLog -ErrorAction Ignore |
  5.     ? PSChildName -NE 'Security' | % PSChildName -pv LN |
  6.     % {
  7.         Get-ChildItem HKLM:\SYSTEM\CurrentControlSet\Services\EventLog\$LN -ErrorAction Ignore |
  8.         % PSChildName | % {
  9.             [PSCustomObject]@{ Source = $_; LogName = $LN }
  10.         }
  11.     }
  12.     if ($LogName) { $x = $x | ? LogName -EQ $LogName }
  13.     $x | ? Source -Like $Name
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement