Skip to content

Instantly share code, notes, and snippets.

@lechup
Last active November 30, 2022 14:09
Show Gist options
  • Save lechup/12358fb869fdcc64cfb761e900a4b700 to your computer and use it in GitHub Desktop.
Save lechup/12358fb869fdcc64cfb761e900a4b700 to your computer and use it in GitHub Desktop.
Scripts to manage backup on Windows 10 machines
# Set-ExecutionPolicy Bypass -Scope Process -Force; or use run.bat
$cred = Import-Clixml .\backup.cred
iex "wbadmin start backup -allCritical -backupTarget:\\backup-server.lan\backup\komputery\ -user:$($cred.UserName) -password:$($cred.GetNetworkCredential().password) -quiet > .\backup.log"
# Set-ExecutionPolicy Bypass -Scope Process -Force; or use run.bat
param(
[string]$credFile
)
if($credFile -ne '') {
Get-Credential | Export-Clixml $credFile
}
# Set-ExecutionPolicy Bypass -Scope Process -Force; or use run.bat
$cred = Import-Clixml .\backup.cred
iex "net use Z: \\backup-server.lan\backup /Persistent:No /user:$($cred.UserName) $($cred.GetNetworkCredential().password)" > $null
# eg. run.bat backup.ps1
@echo off
powershell.exe -noprofile -executionpolicy bypass -WindowStyle hidden -file %1
# Set-ExecutionPolicy Bypass -Scope Process -Force; or use run.bat
net use /delete * /Y > $null
# eg once a week
cmd.exe /c start "backup" /MIN /LOW run.bat backup.ps1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment