Last active
August 2, 2017 01:05
-
-
Save ctrl-freak/29585a09b4fd4da6d1490c3281130ac5 to your computer and use it in GitHub Desktop.
PowerShell Output Timestamping: Write-Log
This file contains hidden or 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 Write-Log($string, $color) { | |
| # Colors: [enum]::GetValues([System.ConsoleColor]) | Foreach-Object {Write-Host $_ -ForegroundColor $_} | |
| $timestamp = Get-Date -Format "s" | |
| $oldFGcolor = $host.ui.RawUI.ForegroundColor | |
| if ($color -ne $null) { | |
| $host.ui.RawUI.ForegroundColor = $color | |
| Write-Output ("["+$timestamp+"] " + $string) | |
| $host.ui.RawUI.ForegroundColor = $oldFGcolor | |
| } else { | |
| Write-Output ("["+$timestamp+"] " + $string) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment