Created
August 3, 2017 02:01
-
-
Save kevinblumenfeld/f2f489d63cf010504cdc9ea09ad92d1f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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