Skip to content

Instantly share code, notes, and snippets.

@ashdar
Last active June 14, 2025 16:16
Show Gist options
  • Save ashdar/abc1465adf6945f1d5a3a6b12ccc0c7b to your computer and use it in GitHub Desktop.
Save ashdar/abc1465adf6945f1d5a3a6b12ccc0c7b to your computer and use it in GitHub Desktop.
Simple Write to a Log from a CMD file
@REM This will work from a .BAT or .CMD file, or from the CMD console.
@REM It's too slow to be used for regular work but it's OK for debugging and troubleshooting.
@REM It's mainly about enforcing a standard format to make it easier to parse the log file later.
PowerShell -noprofile -nologo -command "$LogLevel = 'INFO'; $Message = 'Something notable happened';$OutputTemplate = '{0},{1},{2},{3}'; Add-Content -path .\Simple.log.txt -value ($OutputTemplate -f @((Get-Date).ToString('s'), $LogLevel, $ENV:UserName, $Message) ) "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment