OpsaC - Operating as PowerShell code
published: November 26, 2014 author: Tinu tags: Logging - Scripttemplate categories: PowerShell
Entweder in ein Logfile oder in das Eventlog. Mit nachfolgender Möglichkeit wird in ein Logfile auf dem Computer geschrieben.
<#
[INFORMATION]
[ WARNING ]
[ ERROR ]
#>
$script:Scriptpath = Split-Path -Parent $MyInvocation.MyCommand.Path
$script:Scriptname = $MyInvocation.MyCommand.ToString()
$script:Basename = $script:Scriptname.Remove($script:Scriptname.Length -4)
$script:Logpath = "C:\Admin\Logs\$($script:Basename)"
$script:Logfile = "$($script:Logpath)\$($script:Basename).log"
"$(Get-Date -DisplayHint DateTime) [INFORMATION] Start $($script:Scriptname)" | Out-File -FilePath $script:Logfile -Append -Encoding default
"$(Get-Date -DisplayHint DateTime) [ WARNING ] Start $($script:Scriptname)" | Out-File -FilePath $script:Logfile -Append -Encoding default
"$(Get-Date -DisplayHint DateTime) [ ERROR ] Start $($script:Scriptname)" | Out-File -FilePath $script:Logfile -Append -Encoding default