Skip to content
This repository was archived by the owner on Aug 2, 2023. It is now read-only.

Commit 3badfbc

Browse files
author
Reed Williams
committed
Addressed usability issues
Separted all from header functionality. Validate GUID. Updated examples and documention.
1 parent 62e0870 commit 3badfbc

2 files changed

Lines changed: 47 additions & 30 deletions

File tree

AdfsEventsModule.psm1

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,20 @@ function AggregateOutputObject
316316

317317
[parameter(Mandatory=$true,Position=2)]
318318
[AllowEmptyCollection()]
319-
[PSObject[]]$Headers)
319+
[PSObject[]]$Headers,
320+
321+
[parameter(Mandatory=$false, Position=3)]
322+
[bool]$AddHeaders)
320323

321324
$Output = New-Object PSObject -Property @{
322325
"CorrelationID" = $CorrID
323326
"Events" = $Events
324-
"Headers" = $Headers
325327
}
328+
if($AddHeaders)
329+
{
330+
$Output | Add-Member Headers $Headers
331+
}
332+
326333
Write-Output $Output
327334
}
328335

@@ -381,13 +388,15 @@ function Get-ADFSEvents
381388
time conversions will be based on the UTC of these values.
382389
383390
.EXAMPLE
384-
Get-ADFSEvents -Logs Security, Admin, Debug -CorrelationID 669bced6-d6ae-4e69-889b-09ceb8db78c9 -Servers LocalHost, MyServer
391+
Get-ADFSEvents -Logs Security, Admin, Debug -CorrelationID 669bced6-d6ae-4e69-889b-09ceb8db78c9 -Server LocalHost, MyServer
392+
.Example
393+
Get-ADFSEvents -CorrelationID 669bced6-d6ae-4e69-889b-09ceb8db78c9 -Headers
385394
.EXAMPLE
386-
Get-ADFSEvents -Logs Admin -AllWithHeaders -Servers LocalHost
395+
Get-ADFSEvents -Logs Admin -All
387396
.EXAMPLE
388-
Get-ADFSEvents -Logs Debug, Security -AllWithoutHeaders -Servers LocalHost, Server1, Server2
397+
Get-ADFSEvents -Logs Debug, Security -All -Headers -Server LocalHost, Server1, Server2
389398
.Example
390-
Get-ADFSEvents -Logs Debug -StartTime $start -EndTime $End -server localhost
399+
Get-ADFSEvents -Logs Debug -StartTime (Get-Date -Date ("2017-09-14T18:37:26.910168700Z")) -EndTime (Get-Date) -Headers
391400
392401
#>
393402

@@ -403,18 +412,18 @@ function Get-ADFSEvents
403412
[ValidateNotNullOrEmpty()]
404413
[string]$CorrelationID,
405414

406-
[parameter(Mandatory=$true, Position=1, ParameterSetName="AllEventsWithoutHeaderSet")]
407-
[switch]$AllWithoutHeaders,
408-
409-
[parameter(Mandatory=$true, Position=1, ParameterSetName ="AllEventsWithHeaderSet")]
410-
[switch]$AllWithHeaders,
415+
[parameter(Mandatory=$true, Position=1, ParameterSetName="AllEventsSet")]
416+
[switch]$All,
411417

412418
[parameter(Mandatory=$true, Position=1, ParameterSetName="AllEventsByTimeSet")]
413419
[DateTime]$StartTime,
414420

415421
[parameter(Mandatory=$true, Position=2, ParameterSetName="AllEventsByTimeSet")]
416422
[DateTime]$EndTime,
417423

424+
[parameter(Mandatory=$false)]
425+
[switch]$Headers,
426+
418427
[parameter(Mandatory=$false, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True)]
419428
[string[]]$Server="LocalHost"
420429
)
@@ -423,6 +432,12 @@ function Get-ADFSEvents
423432
{
424433
$ServerList = @()
425434
$HashTable = @{}
435+
$Var = [ref] [System.Guid]::NewGuid()
436+
if($CorrelationID -ne "" -and ![System.Guid]::TryParse($CorrelationID, $Var)){ #Validate provided Correlation ID is a valid GUID
437+
Write-Error "Invalid correlation id. Please provide valid input"
438+
Break
439+
}
440+
426441
if($StartTime -ne $null -and $EndTime -ne $null)
427442
{
428443
$ByTime = $true
@@ -445,7 +460,7 @@ function Get-ADFSEvents
445460
{
446461
$Session = New-PSSession -ComputerName $Server
447462
$Events += QueryDesiredLogs -CorrID $CorrelationID -Session $Session -ByTime $ByTime -Start $StartTime.ToUniversalTime() -End $EndTime.ToUniversalTime()
448-
if($CorrelationID -ne "")
463+
if($CorrelationID -ne "" -and $Headers)
449464
{
450465
$HTTPInformation += GetHTTPRequestInformation -CorrID $CorrelationID -Session $Session
451466
}
@@ -483,7 +498,7 @@ function Get-ADFSEvents
483498

484499
else #Events gathered for a single correlation id
485500
{
486-
AggregateOutputObject -CorrID $CorrelationID -Events $Events -Headers $HTTPInformation
501+
AggregateOutputObject -CorrID $CorrelationID -Events $Events -Headers $HTTPInformation -AddHeader $Headers.IsPresent
487502
}
488503

489504
}
@@ -493,12 +508,13 @@ function Get-ADFSEvents
493508
#Print the result of gathering events for all correlation ids
494509
foreach($EventList in $HashTable.Values)
495510
{
496-
if($AllWithoutHeaders)
511+
<# if(!$Headers)
497512
{
498-
Write-Output $EventList
513+
AggregateOutputObject -CorrID $EventList[0].CorrelationID -Events $EventList -Headers []
499514
}
515+
#>
500516

501-
else{ #Gather headers for each correlation id from each server
517+
if($Headers){ #Gather headers for each correlation id from each server
502518
foreach($Machine in $ServerList)
503519
{
504520
$HTTPInformation = @()
@@ -518,13 +534,13 @@ function Get-ADFSEvents
518534
Remove-PSSession $Session
519535
}
520536
}
521-
}
522-
AggregateOutputObject -CorrID $EventList[0].CorrelationID -Events $EventList -Headers $HTTPInformation
537+
}
523538
}
539+
AggregateOutputObject -CorrID $EventList[0].CorrelationID -Events $EventList -Headers $HTTPInformation -AddHeaders $Headers.IsPresent
524540
}
525541
}
526542

527543

528544
}
529545
Export-ModuleMember -Function Get-ADFSEvents
530-
Export-ModuleMember -Function Write-ADFSEventsSummary
546+
Export-ModuleMember -Function Write-ADFSEventsSummarys

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,32 @@ in.
2828
* __Logs__ - A list of AD FS logs to include in the aggregation. Current options are: "Admin", "Debug", "Security".
2929
The default will pull from both Security and Admin.
3030
* __CorrelationID__ - The correlation ID for a single request. This will aggregate all chosen logs for this request
31-
* __AllWithoutHeaders__ - this flag will cause all requests to be grouped by correlation ID, but the HTTP headers
32-
will not be extracted from the logs
33-
* __AllWithHeaders__ - this flag will cause all requests to be grouped by correlation ID, and the HTTP headers of
34-
each request will be extracted from the logs
35-
* __StartTime__ - the UTC start time to use when aggregating multiple requests. All requests that start after this
31+
* __All__ - This flag will cause all events in the desired logs to be grouped by correlation ID.
32+
* __Headers__ - This flag can be combined with any means of event collection (a single correlation id, all events, or
33+
time based) to reconstruct available HTTP requests and responses.
34+
* __StartTime__ - The UTC start time to use when aggregating multiple requests. All requests that start after this
3635
time will be aggregated
37-
* __EndTime__ - the UTC end time to use when aggregating multiple requests. All requests that end before this time
36+
* __EndTime__ - The UTC end time to use when aggregating multiple requests. All requests that end before this time
3837
will be aggregated
39-
* __Server__ - a comma-separated list of server names to pull logs from.
38+
* __Server__ - A comma-separated list of server names to pull logs from.
4039
The default will pull from LocalHost
4140

4241
## Get-ADFSEvents Output
4342

44-
The output produced by Get-ADFSEvents is a list of objects with each containing the following properties:
43+
The output produced by Get-ADFSEvents is a list of objects with each containing at least the following properties:
4544

4645
1. __CorrelationID__
4746
2. __Events__
48-
3. __Headers__
47+
4948

5049
The __CorrelationID__ property contains a string representation of the Correlation ID that all events and headers within that object share.
5150

5251
The __Events__ property contains a list of [EventLogRecord](https://msdn.microsoft.com/en-us/library/system.diagnostics.eventing.reader.eventlogrecord)
5352
objects for the matching Correlation ID.
5453

55-
The __Headers__ property contains a list of objects, each containing of the following properties:
54+
If the __Headers__ flag is included in the cmdlet's invocation, the output object will also contain a __Headers__ property.
55+
56+
The __Headers__ property contains a list of objects, each containing the following properties:
5657

5758
1. __QueryString__
5859
2. __ResponseString__
@@ -80,7 +81,7 @@ The __ResponseHeader__ property is a dictionary containing the headers included
8081

8182
EXAMPLE: Retrieve all logs from two servers for a specific request
8283

83-
```$logs = Get-ADFSEvents -Logs Security, Admin, Debug -CorrelationID 0c0fd6ee-4b1e-4260-0300-0080070000e3 -Server LocalHost, MyServer```
84+
```$logs = Get-ADFSEvents -Logs Security, Admin, Debug -CorrelationID 0c0fd6ee-4b1e-4260-0300-0080070000e3 -Headers -Server LocalHost, MyServer```
8485

8586
OUTPUT:
8687

0 commit comments

Comments
 (0)