function Write-Log { [CmdletBinding()] Param ( [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)] [ValidateNotNullOrEmpty()] [Alias("LogContent")] [string]$Message, [Parameter(Mandatory=$false)] [Alias('LogPath')] [string]$Path="$ScriptDir\log\$($LOGDATE)$($ini.general.logfile)", [Parameter(Mandatory=$false)] [ValidateSet("Error","Warn","Info")] [string]$Level="Info", [Parameter(Mandatory=$false)] [switch]$NoClobber ) Begin { # Zeige Fehler in Konsole an # $VerbosePreference = 'Continue' } Process { $FormattedDate = Get-Date -Format "yyyy-MM-dd HH:mm:ss" switch ($Level) { 'Error' { Write-Error $Message $LevelText = "[$($OWNPID)] ERROR:" } 'Warn' { Write-Warning $Message $LevelText = "[$($OWNPID)] WARNING:" } 'Info' { Write-Verbose $Message $LevelText = "[$($OWNPID)] INFO:" } } # Schreibe Log in $Path if (!(Test-Path $Path)) { "$FormattedDate $LevelText $Message" | Out-File -Encoding "UTF8" -FilePath $Path } else { "$FormattedDate $LevelText $Message" | Out-File -Encoding "UTF8" -FilePath $Path -Append } } End { } }