# Funktion: speichert den aktuellen Pfad(vgl. pwd) in Get-ScriptDirectory function Get-ScriptDirectory { $Invocation = (Get-Variable MyInvocation -Scope 1).Value Split-Path $Invocation.MyCommand.Path } # Funktion: setze Timestamp, mit Rückgabewert function get-timestamp{ $timestamp = (get-date -Format yyyy_MM_dd__HH_mm_ss) return $timestamp } # restliche Variablen $timestamp = get-timestamp # Ruft Funktion get-timestamp auf $scriptpfad = Get-ScriptDirectory # setzt $scriptpfad auf den Wert von Get-ScriptDirectory # Hostname $hostname_ist = $env:computername $hostname_soll = "irantu" # Ziele/Quellen $quelle2 = "C:\Portable_Programme" $quelle3 = "C:\Users\mg\Desktop" $quelle2_name = "programme" $quelle3_name = "desktop" $quell4_name = "proxmox" $ziel2="$scriptpfad\$hostname_ist\Portable_Programme" $ziel3="$scriptpfad\$hostname_ist\Desktop" # Hostname prüfen if ($hostname_ist -eq $hostname_soll) { Write-Host "Host = $hostname_ist" } else { Write-Host "Falscher Host(SOLL: '$hostname_soll' IST:$hostname_ist)" start-sleep 5 Exit 1 } # logs Ordner erstellen If(!(test-path $scriptpfad\logs)) { New-Item -ItemType Directory -Force -Path $scriptpfad\logs } robocopy $quelle2 $ziel2 /MIR /R:3 /W:10 /DST /TEE /UNILOG+:"$scriptpfad\logs\$timestamp-$quelle2_name.log" robocopy $quelle3 $ziel3 /MIR /R:3 /W:10 /DST /TEE /UNILOG+:"$scriptpfad\logs\$timestamp-$quelle3_name.log"