Skip to content

Instantly share code, notes, and snippets.

@markwragg
Created June 26, 2017 21:05
Show Gist options
  • Save markwragg/f3ac7bd6098dec485e8f11c1fd056fad to your computer and use it in GitHub Desktop.
Save markwragg/f3ac7bd6098dec485e8f11c1fd056fad to your computer and use it in GitHub Desktop.
Simple PowerShell logging function with timestamp, redirects messages to a log file and the verbose stream.
function Write-Log {
Param(
$Message,
$Path = "$env:USERPROFILE\log.txt"
)
function TS {Get-Date -Format 'hh:mm:ss'}
"[$(TS)]$Message" | Tee-Object -FilePath $Path -Append | Write-Verbose
}
Write-Log 'Some message'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment