Skip to content

Instantly share code, notes, and snippets.

@ctrl-freak
Last active August 2, 2017 01:05
Show Gist options
  • Select an option

  • Save ctrl-freak/29585a09b4fd4da6d1490c3281130ac5 to your computer and use it in GitHub Desktop.

Select an option

Save ctrl-freak/29585a09b4fd4da6d1490c3281130ac5 to your computer and use it in GitHub Desktop.
PowerShell Output Timestamping: Write-Log
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