@@ -446,47 +446,41 @@ function Get-ADFSEvents
446446 [string []]$Server = " LocalHost"
447447 )
448448
449- Begin
450- {
451- $ServerList = @ ()
452- $HashTable = @ {}
453- $Var = [ref ] [System.Guid ]::NewGuid()
454- if ($CorrelationID -ne " " -and ! [System.Guid ]::TryParse($CorrelationID , $Var )){ # Validate provided Correlation ID is a valid GUID
455- Write-Error " Invalid correlation id. Please provide valid input"
456- Break
457- }
449+
450+ $ServerList = @ ()
451+ $HashTable = @ {}
452+ $Var = [ref ] [System.Guid ]::NewGuid()
453+ if ($CorrelationID -ne " " -and ! [System.Guid ]::TryParse($CorrelationID , $Var )){ # Validate provided Correlation ID is a valid GUID
454+ Write-Error " Invalid correlation id. Please provide valid input"
455+ Break
456+ }
458457
459- if ($StartTime -ne $null -and $EndTime -ne $null )
460- {
461- $ByTime = $true
462- }
463- else
464- {
465- $ByTime = $false
466- # Set values to prevent binding issues when passing parameters
467- $StartTime = Get-Date
468- $EndTime = Get-Date
469- }
458+ if ($StartTime -ne $null -and $EndTime -ne $null )
459+ {
460+ $ByTime = $true
470461 }
462+ else
463+ {
464+ $ByTime = $false
465+ # Set values to prevent binding issues when passing parameters
466+ $StartTime = Get-Date
467+ $EndTime = Get-Date
468+ }
469+
471470
472- Process
471+ foreach ( $Machine in $Server )
473472 {
474- $ServerList += $Server
473+ $ServerList += $Machine
475474 $Events = @ ()
476475 $HTTPInformation = @ ()
477476 Try
478477 {
479- $Session = New-PSSession - ComputerName $Server
480- $Events += QueryDesiredLogs - CorrID $CorrelationID - Session $Session - ByTime $ByTime - Start $StartTime.ToUniversalTime () - End $EndTime.ToUniversalTime ()
481- if ($CorrelationID -ne " " -and $Headers )
482- {
483- $HTTPInformation += GetHTTPRequestInformation - CorrID $CorrelationID - Session $Session
484- }
485-
478+ $Session = New-PSSession - ComputerName $Machine
479+ $Events += QueryDesiredLogs - CorrID $CorrelationID - Session $Session - ByTime $ByTime - Start $StartTime.ToUniversalTime () - End $EndTime.ToUniversalTime ()
486480 }
487481 Catch
488482 {
489- Write-Warning " Error collecting events from $Server . Error: $_ "
483+ Write-Warning " Error collecting events from $Machine . Error: $_ "
490484 }
491485 Finally
492486 {
@@ -495,65 +489,57 @@ function Get-ADFSEvents
495489 Remove-PSSession $Session
496490 }
497491 }
498- if ($CorrelationID -eq " " )
492+
493+ foreach ($Event in $Events )
499494 {
500- foreach ($Event in $Events )
501- {
502- $ID = [string ] $Event.CorrelationID
495+ $ID = [string ] $Event.CorrelationID
503496
504- if (! [string ]::IsNullOrEmpty($ID ) -and $HashTable.Contains ($ID )) # Add event to exisiting list
505- {
506- $HashTable .$ID = $HashTable .$ID + $Event
507- }
508-
509- elseif (! [string ]::IsNullOrEmpty($ID ))
510- {
511- $HashTable .$ID = @ () + $Event # Add correlation ID and fist event to hashtable
512- }
497+ if (! [string ]::IsNullOrEmpty($ID ) -and $HashTable.Contains ($ID )) # Add event to exisiting list
498+ {
499+ $HashTable .$ID = $HashTable .$ID + $Event
500+ }
513501
502+ elseif (! [string ]::IsNullOrEmpty($ID ))
503+ {
504+ $HashTable .$ID = @ () + $Event # Add correlation ID and fist event to hashtable
514505 }
515- }
516506
517- else # Events gathered for a single correlation id
518- {
519- AggregateOutputObject - CorrID $CorrelationID - Events $Events - Headers $HTTPInformation - AddHeader $Headers.IsPresent
520507 }
521-
508+
522509 }
523510
524- End
511+
512+ # Print the result of gathering events for all correlation ids
513+ foreach ($EventList in $HashTable.Values )
525514 {
526- # Print the result of gathering events for all correlation ids
527- foreach ($EventList in $HashTable.Values )
528- {
529515
530- if ($Headers ){ # Gather headers for each correlation id from each server
531- foreach ($Machine in $ServerList )
516+ if ($Headers ){ # Gather headers for each correlation id from each server
517+ foreach ($Machine in $ServerList )
518+ {
519+ $HTTPInformation = @ ()
520+ try
532521 {
533- $HTTPInformation = @ ()
534- try
535- {
536- $Session = New-PSSession - ComputerName $Machine
537- $HTTPInformation += GetHTTPRequestInformation - CorrID $EventList [0 ].CorrelationID - Session $Session
538- }
539- Catch
522+ $Session = New-PSSession - ComputerName $Machine
523+ $HTTPInformation += GetHTTPRequestInformation - CorrID $EventList [0 ].CorrelationID - Session $Session
524+ }
525+ Catch
526+ {
527+ Write-Warning " Error collecting HTTP traffic from $Machine . Error: $_ "
528+ }
529+ Finally
530+ {
531+ if ($Session )
540532 {
541- Write-Warning " Error collecting HTTP traffic from $Server . Error: $_ "
533+ Remove-PSSession $Session
542534 }
543- Finally
544- {
545- if ($Session )
546- {
547- Remove-PSSession $Session
548- }
549- }
550535 }
551- }
552- AggregateOutputObject - CorrID $EventList [0 ].CorrelationID - Events $EventList - Headers $HTTPInformation - AddHeaders $Headers.IsPresent
536+ }
553537 }
538+ AggregateOutputObject - CorrID $EventList [0 ].CorrelationID - Events $EventList - Headers $HTTPInformation - AddHeaders $Headers.IsPresent
554539 }
555540
541+
556542
557543}
558544Export-ModuleMember - Function Get-ADFSEvents
559- Export-ModuleMember - Function Write-ADFSEventsSummarys
545+ Export-ModuleMember - Function Write-ADFSEventsSummary
0 commit comments