<# .SYNOPSIS Run as ADMIN Creats Zip-Backup of everything inside Notes folder .PARAMETER targetEnv the target folder to move zip file to. Possible Values: LOCAL, SWAG, ATB. If no parameter is supplied, the zip file will be located in the same folder as this script. .EXAMPLE .\backup_notes.ps1 LOCAL .NOTES Author: Marcel Dechert #> param ( [ValidateSet('LOCAL','SWAG','ATB')] [String] $targetEnv ) # Backup Targets # 1. Local # 2. ATB Network drive # 3. Swaghausen Network drive $pathToFolder = switch ($targetEnv) { LOCAL { "C:\Users\dechert\Notizen_Backup\" } SWAG { "\\Swaghausen-WG\homes\marcelo\ATB\Notizen-Backups\" } ATB { "https://locmanacc.europoolsystem.com/locman/api/zones" } } Write-Host "Starting to zip notes folder... Target folder will be: $pathToFolder" $7zipPath = "$env:ProgramFiles\7-Zip\7z.exe" if (-not (Test-Path -Path $7zipPath -PathType Leaf)) { throw "7 zip file '$7zipPath' not found" } Set-Alias 7zip $7zipPath $Source = "C:\Users\dechert\Notizen" $currentDate = get-date -f MM-dd-yyyy_HH_mm_ss $targetFilename = "Notizen_Backup_" + $currentDate + ".zip" $zipTarget = $targetFilename # mx=9 is maximum compression level 7zip a -mx=9 $zipTarget $Source # use Robocopy to move files to target folder # robocopy . "\\Swaghausen-WG\homes\marcelo\ATB\Notizen-Backups\" "Notizen_Backup_12-15-2021_15_25_40.zip" /Z /r:60 /w:5 /MIR /MT:64 /NFL # TODO print progress: https://stackoverflow.com/questions/13883404/custom-robocopy-progress-bar-in-powershell robocopy . $pathToFolder $zipTarget /Z /r:60 /w:5 /MIR /MT:64 /NFL # delete zip file in local folder if successfull Remove-Item $zipTarget