Untitled
unknown
plain_text
a year ago
1.4 kB
4
Indexable
param ( [string]$FileName ) # Check if the file exists if (-not (Test-Path $FileName -PathType Leaf)) { Write-Host "File '$FileName' does not exist." exit } # Read the content of the file $content = Get-Content -Path $FileName # Define regex patterns for extracting client and host information $clientPattern = "client:\s*'(\d+)'" $hostPattern = "host\s*'([^']*)'" # Array to store extracted information $extractedInfo = @() # Loop through each line of text foreach ($line in $content) { # Match client number $clientMatch = [regex]::Match($line, $clientPattern) if ($clientMatch.Success) { $clientNumber = $clientMatch.Groups[1].Value } else { $clientNumber = "N/A" } # Match host information $hostMatch = [regex]::Match($line, $hostPattern) if ($hostMatch.Success) { $hostInfo = $hostMatch.Groups[1].Value } else { $hostInfo = "N/A" } # Add extracted information to the array $extractedInfo += [PSCustomObject]@{ Client = $clientNumber Host = $hostInfo } } # Output the extracted information $outputFileName = "$([System.IO.Path]::GetFileNameWithoutExtension($FileName))_extracted.txt" $extractedInfo | Export-Csv -Path $outputFileName -NoTypeInformation Write-Host "Extracted information written to '$outputFileName'"
Editor is loading...
Leave a Comment