migrate to git.charlotte.sh
This commit is contained in:
commit
fbd588721e
412 changed files with 13750 additions and 0 deletions
26
automation-sys320/week04/ParsingApacheLogs.ps1
Normal file
26
automation-sys320/week04/ParsingApacheLogs.ps1
Normal file
|
@ -0,0 +1,26 @@
|
|||
# 9/26/24
|
||||
|
||||
# parses apache log into pscustomobjects, filters IPs for 10.*
|
||||
function ApacheLogs1(){
|
||||
$logsnotformatted = Get-Content C:\xampp\apache\logs\access.log
|
||||
$tablerecords = @()
|
||||
|
||||
for($i=0; $i -lt $logsnotformatted.Length; $i++){
|
||||
|
||||
# split string into words
|
||||
$words = $logsnotformatted[$i] -split " "
|
||||
|
||||
$tablerecords += [pscustomobject]@{"IP" = $words[0]; `
|
||||
"Time" = $words[3].Trim('['); `
|
||||
"Method" = $words[5].Trim('"'); `
|
||||
"Page" = $words[6]; `
|
||||
"Protocol" = $words[7]; `
|
||||
"Response" = $words[8]; `
|
||||
"Referrer" = $words[10]; `
|
||||
"Client" = -join $words[11..($words.Length - 1)]; }
|
||||
}# end of for loop
|
||||
|
||||
return $tablerecords | Where-Object { $_.IP -ilike "10.*"}
|
||||
}
|
||||
$tablerecords = ApacheLogs1
|
||||
#$tablerecords
|
Loading…
Add table
Add a link
Reference in a new issue