45 lines
1.4 KiB
PowerShell
45 lines
1.4 KiB
PowerShell
# 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
|
|
# Hhostname
|
|
$hostname_ist = $env:computername
|
|
$hostname_soll = "irantu"
|
|
|
|
# Ziele/Quellen
|
|
$quelle1 = "C:\VM"
|
|
$quelle2 = "C:\Portable_Programme"
|
|
$quelle3 = "C:\Users\mg\Desktop"
|
|
$quelle1_name = "vm"
|
|
$quelle2_name = "programme"
|
|
$quelle3_name = "desktop"
|
|
$ziel1="$scriptpfad\$hostname_ist\VM"
|
|
$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
|
|
}
|
|
|
|
|
|
robocopy $quelle1 $ziel1 /MIR /R:3 /W:10 /DST /TEE /UNILOG+:"$scriptpfad\logs\$timestamp-$quelle1_name.log"
|
|
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"
|