Tinus EngOps Wiki

Logo

OpsaC - Operating as PowerShell code

Links

Home

IT-Wiki

PowerShell Blog

PowerShell Index

PowerShell Search

Additional Websites

View my GitHub Profile

View my GitHub Gists

View my Codeberg Page

View my Photo Website

Script Logging

published: November 26, 2014 author: Tinu tags: Logging - Scripttemplate categories: PowerShell


Jedes Script schreibt ein Log

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


← Previous Post ◇ [ Top ] ◇ Copyright © 2024 by tinuwalther ◇ [ Blog ] ◇ Next Post →