Skip to content

Instantly share code, notes, and snippets.

@LarryWeiss
Created February 27, 2019 19:32
Show Gist options
  • Save LarryWeiss/c079a80aed8571ba5cf81fffe5922b5c to your computer and use it in GitHub Desktop.
Save LarryWeiss/c079a80aed8571ba5cf81fffe5922b5c to your computer and use it in GitHub Desktop.
uninterruptible PowerShell code
function Logs
{
$lineNumber = 0
$delimiter = ":"
$dateTimeStamp = "00-00-0000 00:00:00.000"
Get-ChildItem Log?.txt |
ForEach-Object {
$filename = $_.name
Get-Content $filename | ForEach-Object {
if ([System.Console]::KeyAvailable) { return } # <-- this makes it interruptable
$s = $_
$lineNumber++
$LineNumberText = $('{0:d8}' -f $lineNumber)
if ( ($s.length -ge 30) )
{
$dateTimeStamp = $s.Substring(5, 23)
}
" " + $dateTimeStamp + " " + $filename + " " + $LineNumberText + " " + $delimiter + " " + $s
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment