log-dir wird erstellt wenn nicht vorhanden

This commit is contained in:
scriptos 2023-11-30 10:37:04 +01:00
parent 0313ac610d
commit 53a67af988

View File

@ -5,20 +5,25 @@
# Autor: Patrick Asmus # Autor: Patrick Asmus
# Web: https://www.media-techport.de # Web: https://www.media-techport.de
# Git-Reposit.: https://git.media-techport.de/scriptos/windows-updater.git # Git-Reposit.: https://git.media-techport.de/scriptos/windows-updater.git
# Version: 1.0 # Version: 1.1
# Datum: 29.11.2023 # Datum: 30.11.2023
# Modifikation: Erste Veröffentlichung # Modifikation: log-dir wird erstellt wenn nicht vorhanden
##################################################### #####################################################
# Variablen
$LogPfad = "C:\logs\windows-updater.log"
$ModulVerzeichnis = Join-Path -Path $PSScriptRoot -ChildPath "Modules"
$env:PSModulePath += ";$ModulVerzeichnis"
# Funktion zur Formatierung des Datums im deutschen Stil # Funktion zur Formatierung des Datums im deutschen Stil
function Format-DeutschesDatum ([datetime] $date) { function Format-DeutschesDatum ([datetime] $date) {
return $date.ToString("dd.MM.yyyy HH:mm:ss") return $date.ToString("dd.MM.yyyy HH:mm:ss")
} }
# Variablen # Überprüfe, ob der Log-Ordner existiert, andernfalls erstelle ihn
$LogPfad = "C:\logs\windows-updater.log" if (-not (Test-Path -Path $LogPfad)) {
$ModulVerzeichnis = Join-Path -Path $PSScriptRoot -ChildPath "Modules" New-Item -ItemType Directory -Path (Split-Path $LogPfad) -Force
$env:PSModulePath += ";$ModulVerzeichnis" }
# Zeitstempel für das Logfile # Zeitstempel für das Logfile
$LogZeitstempel = Format-DeutschesDatum (Get-Date) $LogZeitstempel = Format-DeutschesDatum (Get-Date)