Created
February 27, 2019 19:32
-
-
Save LarryWeiss/c079a80aed8571ba5cf81fffe5922b5c to your computer and use it in GitHub Desktop.
uninterruptible PowerShell code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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