Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kevinblumenfeld/f2f489d63cf010504cdc9ea09ad92d1f to your computer and use it in GitHub Desktop.
Save kevinblumenfeld/f2f489d63cf010504cdc9ea09ad92d1f to your computer and use it in GitHub Desktop.
function Get-Events {
<#
.SYNOPSIS
.DESCRIPTION
.EXAMPLE
get-content ./hostnames.txt | Get-Event -EventID 1034 -NumberofNewestIDs 100
#>
Param (
[Parameter(Mandatory = $true,
ValueFromPipeline = $true)]
[string[]] $Computers,
[Parameter(Mandatory = $true)]
[int] $EventID,
[Parameter(Mandatory = $true)]
[int] $NumberOfNewestIDs
)
Begin {
Start-Transcript
$logSuccess = ($(get-date -Format yyyy-MM-dd_HH-mm-ss) + "_eventIDs.csv")
}
Process {
$_ | % {
Start-Job -ScriptBlock {
$comp = $using:_
$id = $using:eventID
$num = $using:NumberOfNewestIDs
$log = $using:logSuccess
Get-Eventlog -Logname Application -ComputerName $comp -newest $num |
Where-Object {$_.EventID -eq "$id"} |
Select MachineName, Source, EventID, Message | Out-File C:\scripts\$log -Append
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment