Last active
June 14, 2025 16:16
-
-
Save ashdar/abc1465adf6945f1d5a3a6b12ccc0c7b to your computer and use it in GitHub Desktop.
Simple Write to a Log from a CMD file
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
| @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