| external help file | krbtgtRotate-help.xml |
|---|---|
| online version | |
| schema | 2.0.0 |
Writes a timestamped, categorized message to a log file on disk.
Write-LogMessage [-Message] <Object> [[-Caller] <String>] [[-Category] <String>] [[-OutPath] <String>]
[[-FileName] <String>] [-PassThru]
Write-LogMessage appends a formatted, timestamped entry to a log file on disk. Each entry includes the ISO 8601 timestamp, the calling function name, the category (Info, Verbose, Warning, Error, Debug), and the message body.
When called from Invoke-KrbtgtPasswordRotate, the FileName and OutPath are set by the caller so all rotation events land in the same file. The default FileName is a new GUID (e.g., 'c624ff78aa7e41a3ac43973d774dc267.txt') written to $env:Temp.
To locate a log file written with default settings: dir $env:Temp*.txt | Sort-Object LastWriteTime -Descending | Select-Object -First 1
Each log line follows this format: [ ] [ ] [ ]
PS > $paramMessage = @{
Message = "Simple test message"
Caller = "ExampleCaller"
Category = "Verbose"
PassThru = $True
}
PS > Write-LogMessage @paramMessage
[ 2000-05-10T20:15:03.0000000-07:00 ] [ ExampleCaller ] [ Verbose ]
Simple test message
PS > dir $env:Temp
Directory: C:\Users\jdoe\AppData\Local\Temp
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2000-05-10 15:03 96 c624ff78aa7e41a3ac43973d774dc267.txt
The message is formatted and written to the log, created by default in the 'Temp' folder.
PS > Write-LogMessage -Message "Halting error encountered on DC01" `
-Caller "Invoke-KrbtgtPasswordRotate" `
-Category "Error" `
-OutPath "C:\logs\krbtgtRotate" `
-FileName "2026-03-01T14.30.00-krbtgtRotate.txt"
Appends an Error-category entry to a named log file in the specified path. If OutPath does not exist or is not writable, the log falls back to $env:Temp with a warning. Use a consistent FileName across multiple Write-LogMessage calls to collect all events for a single rotation run in one file.
Specifies the message content to be written.
Type: Object
Parameter Sets: (All)
Aliases: Content
Required: True
Position: 1
Default value:
Accept pipeline input: True (ByValue)
Accept wildcard characters: FalseSpecifies the source of the message.
Type: String
Parameter Sets: (All)
Aliases: Source
Required: False
Position: 2
Default value:
Accept pipeline input: True (ByValue)
Accept wildcard characters: FalseSpecifies the category of the message; can be Info, Verbose, Warning, Error or Debug.
Type: String
Parameter Sets: (All)
Aliases: Condition
Required: False
Position: 3
Default value: Info
Accept pipeline input: True (ByValue)
Accept wildcard characters: FalseSpecifies the folder where the log file should be written.
Type: String
Parameter Sets: (All)
Aliases: Path
Required: False
Position: 4
Default value: $env:Temp
Accept pipeline input: True (ByValue)
Accept wildcard characters: FalseSpecifies the name of the file for the log.
Type: String
Parameter Sets: (All)
Aliases: Name, Log
Required: False
Position: 5
Default value: "$([Guid]::NewGuid().ToString("n")).txt"
Accept pipeline input: True (ByValue)
Accept wildcard characters: FalseSwitch parameter, specifies that the same content to be written to the log should be sent to the default out view.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False- proper help added
- changing msgLogPath to show only during debug (reduce the noise in verbose)
- rework of several pieces, bumping to v0.2.0 for module
- updated param w/ alias
- added basic error handling for outPath not exist, not able to write to log
- added 'category' param to differentiate messages being received
- removed 'outHost' switch, created duplicate output if 'outHost' and 'passThru' invoked @interactive console
- initial creation