Skip to content

Instantly share code, notes, and snippets.

@pstakuu
Created August 12, 2022 14:09
Show Gist options
  • Save pstakuu/74b24b4a5073f5aee3901c64c0f76dfd to your computer and use it in GitHub Desktop.
Save pstakuu/74b24b4a5073f5aee3901c64c0f76dfd to your computer and use it in GitHub Desktop.
used to parse RADIUS log files
$files= Get-childitem Y: | select -last 90
function Process-RADIUSLogs () {
[CmdletBinding()]
param(
$file,
[switch]$onlyAccepted
)
if ($onlyAccepted) {Write-Verbose "Processing only authenticated attempts"}
Write-Verbose "Processing $file"
$data = get-Content $file
for ($i=0; $i -lt $data.count; $i++) {
if($onlyAccepted) {
$data[$i] -match '".+?",".+?",(?<date>.+?),2,,"(?<distinguishedname>.+?)"' | out-null
if ($matches) {
New-object -TypeName PSObject -Property @{
Date = $matches['date']
DistinguishedName = $matches['distinguishedname']
}
$matches = $Null
}
} else {
$data[$i] -match '"(?<server>.+?)","(?<process>.+?)",(?<date>.+?),(?<status>1|2|3),"(?<username>.+?)","(?<distinguishedname>.+?)","(?<publicIP>.+?)","(?<srcIP>.+?)",' | out-null
if ($matches) {
New-object -TypeName PSObject -Property @{
Date = $matches['date']
Status = $matches['status']
Username = $matches['username']
DistinguishedName = $matches['distinguishedname']
SourceIP = $matches['srcIP']
}
$matches = $Null
}
}
}
}
$results = $files |Foreach {Process-RADIUSLogs -file $_.fullname -verbose -onlyAccepted}
$results | export-csv C:\temp\RADIUSLOGS.csv -NoTypeInformation
Process-RADIUSLogs -file Y:\IN210411.log -onlyAccepted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment