Kae Travis

Simple PowerShell Logging Function

This is a simple PowerShell logging function to write a specified message to a log file in the user’s %temp% folder.

The file in this example is called Filename.log, but can be renamed as appropriate.


function Write-Log {
[CmdletBinding()]
param(
[string]$message
)
try {
"$((Get-Date).tostring('dd/MM/yyyy HH:mm:ss')) - $message" | Out-File "$Env:Temp\Filename.log" -Append
} catch {}
}
Write-Log "Example 1"
Write-Log "Example 2"
Simple PowerShell Logging Function
Simple PowerShell Logging Function

Leave a Reply