Your strategic advantage starts here

Simple PowerShell Logging Function

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"
Related Posts
Leave a Reply
Give us a call

Available from 9am to 8pm, Monday to Friday.

Send us a message

Send your message any time you want.

Our usual reply time: 1 Business day
Give us a call

Available from 9am to 8pm, Monday to Friday.

Send us a message

Send your message any time you want.

Our usual reply time: 1 Business day