forked from jajp777/powershell-scripts-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-Capi2EventLogs.ps1
87 lines (60 loc) · 3.24 KB
/
Get-Capi2EventLogs.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
function Get-Capi2EventLogs {
[CmdletBinding()]
param (
[parameter(ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True)]
[Alias('PSComputerName','DNSHostName','CN','Hostname')]
[string[]]
$ComputerName = $env:COMPUTERNAME
) #param
begin {
if (-not ($PSBoundParameters.ContainsKey('ComputerName'))) {
$ComputerName = $env:COMPUTERNAME
} #if
$Capi2EventFilter = [xml] @"
<QueryList>
<Query Id='0' Path='Microsoft-Windows-CAPI2/Operational'>
<Select Path='Microsoft-Windows-CAPI2/Operational'>
*[System[(Level=1 or Level=2 or Level=3) and TimeCreated[timediff(@SystemTime) <= 86400000]]]
</Select>
</Query>
</QueryList>
"@
} #begin
process {
$ComputerName | ForEach-Object {
$EachComputer = $_
if ($EachComputer -match $env:COMPUTERNAME) {
$SplatArgs = @{ FilterXml = $Capi2EventFilter }
} elseif (-not ($EachComputer -match $env:COMPUTERNAME)) {
$SplatArgs = @{ ComputerName = $ComputerName
FilterXml = $Capi2EventFilter }
} #if
Get-WinEvent @SplatArgs | ForEach-Object {
$EventXml = [xml]$_.ToXml()
$EventXml = $EventXml.Event.UserData.CertVerifyCertificateChainPolicy
$ServerName = $EventXml.SSLAdditionalPolicyInfo.serverName
$ResultText = $EventXml.Result.'#text'
$ProcessName = $EventXml.EventAuxInfo.ProcessName
$Certificate = $EventXml.Certificate.fileRef
$SubjectName = $EventXml.Certificate.subjectName
$CorrelationTaskId = $EventXml.CorrelationAuxInfo.TaskId
New-Object -TypeName psobject -Property @{ 'TimeCreated' = $_.TimeCreated
'Id' = $_.Id
'TaskDisplayName' = $_.TaskDisplayName
'LevelDisplayName' = $_.LevelDisplayName
'MachineName' = $_.MachineName
'ProcessId' = $_.ProcessId
'ThreadId' = $_.ThreadId
'ProcessName' = $ProcessName
'ServerName' = $ServerName
'SubjectName' = $SubjectName
'Certificate' = $Certificate
'ResultText' = $ResultText
'CorrelationTaskId' = $CorrelationTaskId }
} | Select-Object -Property TimeCreated,Id,TaskDisplayName,LevelDisplayName,
MachineName,ProcessId,ThreadId,ProcessName,ServerName,
SubjectName,Certificate,ResultText,CorrelationTaskId
} #ForEach ComputerName
} #process
end {} #end
} #function Get-Capi2EventLogs