Public/Write-LogMessage.ps1
function Write-LogMessage { Param( [Parameter(Mandatory=$true, ValueFromPipeline=$true)] [string]$Message, [Parameter(Mandatory=$false)] [ValidateSet('Verbose','Info','Warning','Error')] [string]$Level = 'Verbose', [Parameter(Mandatory=$false)] [switch]$SkipLogFileOutput, [Parameter(Mandatory=$false)] [switch]$SkipConsoleOutput ) $Message = "$($Level): $((Get-Date).ToString('yyyyMMdd-HHmmss')). $Message" if( !($SkipLogFileOutput.IsPresent) ) { $Message | Out-File $Script:logFile -Force -Append } if( !($SkipConsoleOutput.IsPresent) ) { switch($Level) { 'Verbose' { Write-Verbose $Message -Verbose break } 'Info' { $msg = [System.Management.Automation.HostInformationMessage]@{ Message = $Message ForegroundColor = [System.ConsoleColor]::Green BackgroundColor = $Host.UI.RawUI.BackgroundColor } Write-Information $msg -InformationAction Continue break } 'Warning' { Write-Warning $Message break } 'Error' { Write-Error $Message break } } } } Export-ModuleMember -Function Write-LogMessage |