Log-Action
Description:
Logging function to use in application package/adjustments/shimming scripts.
Language:
Powershell
Usage Type:
Packaging Function
Script Source:
function Log-Action ($Message, $StampDateTime, $WriteHost) { ################################ # Function Version 19.5.11.4 # Function by Sean Huggans ################################ # Function will log the provided message with a timestamp in real time to the configured Log File. # Notes: # - This function is intended for application package scripts, and relies on the $AppName variable to be defined at the start of your script to work. # Usage Examples: # - Log-Action -message "Success!" # - Log-Action -message "---------------------------------------------" -StampDateTime $false $LogFile = "install.log" $LogDir = "C:\Temp\$($AppName)" $LogPath = "$($LogDir)\$($LogFile)" New-Item -ItemType directory -Path $LogDir -Confirm:$false -Force | out-null if (($StampDateTime -eq $false) -or ($StampDateTime -eq "no")) { $Message | Out-File $LogPath -Append } else { "[ $(get-date -Format 'yyyy.MM.dd HH:mm:ss') ] $($Message)" | Out-File $LogPath -Append } if ($WriteHost -eq $true) { Write-Host $Message } }
Note: that all applications posted here are posted for use, both commercial and non-commercial, free of charge, and as such are provided as-is, without warranty of any kind whatsoever. visuaFUSION, FMSCUG or any other program listed here's author are not responsible for any damages or shortcomings that result from usage of any of these applications.