Importing Logging File & Convert to Excel Report.

Iron Contributor

Sharing Mode.

 

Log File (loggingfileV12.txt)

UserName, Product, Date, Computer
UserA, 1, 16-May-22 00:46:51, Computer1
UserB, 2, 16-May-22 03:00:29, Computer2
UserC, 3, 16-May-22 03:01:37, Computer3
UserD, 4, 16-May-22 05:00:33, Computer4

 

Log Extraction using Powershell

# Create Report Array
$report = @()

# Location of the Log File
$logFile = "$($env:USERPROFILE)\Desktop\loggingfileV12.txt"

# Set Date
$startDate = Get-Date "5-16-2022 00:00:00" 
$endDate = Get-Date "5-16-2022 23:59:59"

# Get Content of the Log
$logContents = Import-Csv $logFile | Select-Object -Property @{n="Date"; e={ Get-Date ($_.Date) }}, @{n="Product"; e={ $_.Product }}, @{n="Computer"; e={ $_.Computer }}, @{n="UserName"; e={ $_.UserName }} 

$logContents | Where-Object { $_.Date -gt $startDate -And $_.Date -le $endDate } | Select-Object UserName, Product, Date, Computer | Sort-Object -Property Date | ForEach-Object {

    # Creating Report Header
    $reportdetails = "" | Select UserName, Product, Date, Computer

    $reportdetails.UserName = $_.UserName
    $reportdetails.Product = $_.Product
    $reportdetails.Date = Get-Date $_.Date -f "MM.dd.yyyy hh.mm tt" 
    $reportdetails.Computer = $_.Computer

    $report+=$reportdetails 

}

# View Reports
$report | Export-Excel "$($env:USERPROFILE)\Desktop\Logs_$(get-date -f "MM.dd.yyyy hh.mm tt").xlsx" -AutoSize -TableName Logs -WorksheetName Logs
Write-Host "Finished..."

 

:thumbs_up::thumbs_up::thumbs_up:

 

0 Replies