Simple powershell logging

Small snippet to use for logging events to the file in a powershell script

#Prepare Logging

[string]$LogFolder = "C:\MyLogFolder\"


[string]$InstallationLogFile = "$LogFolder$logfilename"
function f_Logging([string]$Message){

If((Test-Path"$LogFolder") -eq0){

New-Item"$LogFolder"-Type "Directory"-Force


Write-output" $((get-date).tostring("MM.dd.yyyy HH:mm:ss")) $Message "|Out-File-FilePath $InstallationLogFile-Append


and call a function

f_Logging "My message"

Author: G L

Greg's a Senior Database Administrator in Austria with over 15 years of experience in IT (servicedesk/helpdesk, software engineer, database administrator) Likes SQL Server administration, powershell and testing new features

Leave a Reply

Your email address will not be published. Required fields are marked *