Skip to content

Commit

Permalink
Added Find-TroubleshootingEvent script
Browse files Browse the repository at this point in the history
  • Loading branch information
adbertram committed Sep 18, 2016
1 parent dad8fc6 commit 980f38e
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Troubleshooting Tools/Find-TroubleshootingEvent.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
function Find-TroubleshootingEvent
{
[OutputType()]
[CmdletBinding()]
param
(
[Parameter()]
[ValidateNotNullOrEmpty()]
[string[]]$ComputerName = (hostname),

[Parameter()]
[ValidateNotNullOrEmpty()]
[int]$EventId
)
try
{
@($ComputerName).foreach({
$computer = $_
$getEventParams = @{
ComputerName = $computer
}
$logNames = @(Get-WinEvent @getEventParams -ListLog *).where({ $_.RecordCount }).LogName
Write-Verbose -Message "Found log names: [$($logNames -join ',')]"
$filterHashTable = @{
LogName = $logNames
}
if ($PSBoundParameters.ContainsKey('EventId'))
{
$filterHashTable.Id = $EventId
}
$selectProperties = @('*',@{Name = 'ServerName'; Expression = {$computer}})
Get-WinEvent @getEventParams -FilterHashTable $filterHashTable | Select-Object -Property $selectProperties
})
}
catch
{
$PSCmdlet.ThrowTerminatingError($_)
}
}

0 comments on commit 980f38e

Please sign in to comment.