powershell_kopierscripte/laptop-ssd.ps1

63 lines
2.2 KiB
PowerShell
Raw Normal View History

2021-08-09 11:40:04 +02:00
# Funktion: speichert den aktuellen Pfad(vgl. pwd) in Get-ScriptDirectory
2021-03-18 08:29:50 +01:00
function Get-ScriptDirectory {
2021-03-18 09:08:22 +01:00
$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
2021-03-18 08:29:50 +01:00
}
2021-03-18 09:08:22 +01:00
# restliche Variablen
$timestamp = get-timestamp # Ruft Funktion get-timestamp auf
$scriptpfad = Get-ScriptDirectory # setzt $scriptpfad auf den Wert von Get-ScriptDirectory
2021-05-07 08:29:18 +02:00
# Hostname
2021-03-18 08:29:50 +01:00
$hostname_ist = $env:computername
$hostname_soll = "irantu"
2021-03-18 09:08:22 +01:00
# Ziele/Quellen
2021-03-18 08:29:50 +01:00
$quelle1 = "C:\VM"
$quelle2 = "C:\Portable_Programme"
$quelle3 = "C:\Users\mg\Desktop"
2022-04-28 07:58:08 +02:00
$quelle4 = "\\fileserver2.grote.lan\vm\Mint_lol"
2022-05-05 14:08:41 +02:00
$quelle5 = "C:\Users\mg\AppData\Roaming\Apple Computer"
2022-05-26 10:13:56 +02:00
$quelle6 = "\\fileserver2.grote.lan\proxmox"
2021-03-18 09:49:50 +01:00
$quelle1_name = "vm"
$quelle2_name = "programme"
$quelle3_name = "desktop"
2022-04-28 07:58:08 +02:00
$quelle4_name = "mint_lol"
2022-05-05 14:26:34 +02:00
$quelle5_name = "apple"
2022-05-26 10:13:56 +02:00
$quell6_name = "proxmox"
2021-03-18 08:29:50 +01:00
$ziel1="$scriptpfad\$hostname_ist\VM"
$ziel2="$scriptpfad\$hostname_ist\Portable_Programme"
$ziel3="$scriptpfad\$hostname_ist\Desktop"
2022-04-28 07:58:08 +02:00
$ziel4="$scriptpfad\$hostname_ist\mint_lol"
2022-05-05 14:24:27 +02:00
$ziel5="$scriptpfad\$hostname_ist\apple"
2022-05-26 10:13:56 +02:00
$ziel6="$scriptpfad\$hostname_ist\proxmox"
2021-03-18 08:29:50 +01:00
# 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
}
2021-05-07 08:29:01 +02:00
# logs Ordner erstellen
If(!(test-path $scriptpfad\logs))
{
New-Item -ItemType Directory -Force -Path $scriptpfad\logs
}
2021-03-18 08:29:50 +01:00
2021-05-07 08:25:43 +02:00
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"
2022-04-28 07:58:08 +02:00
robocopy $quelle4 $ziel4 /MIR /R:3 /W:10 /DST /TEE /UNILOG+:"$scriptpfad\logs\$timestamp-$quelle4_name.log"
2022-05-05 14:26:34 +02:00
robocopy $quelle5 $ziel5 /MIR /R:3 /W:10 /DST /TEE /UNILOG+:"$scriptpfad\logs\$timestamp-$quelle5_name.log"
2022-05-26 10:13:56 +02:00
robocopy $quelle6 $ziel6 /MIR /R:3 /W:10 /DST /TEE /UNILOG+:"$scriptpfad\logs\$timestamp-$quelle6_name.log"