forked from ChrisTitusTech/powershell-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup.ps1
40 lines (34 loc) · 1.61 KB
/
backup.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Welcome text
Write-Host "Avilable on Github: https://github.com/ChrisTitusTech/powershell-scripts"
# Backup source computer
$sourceComputer = $env:COMPUTERNAME # Grabs the name of the source computer
$backupLocation = "C:\Backup" # Replace with the desired backup location on the source computer
# Backup destination computer
$destinationComputer = "COMPUTER_NAME" # Replace with the name of the destination computer
$restoreLocation = "C:\Restore" # Replace with the desired restore location on the destination computer
# Prompts
$Mode = Read-Host "Manual input? (Y/n)"
if($Mode -eq "Y"){
Read-Host -Prompt "Source Computer Name ($sourceComputer)" -OutVariable $tmp
if($tmp -ne ""){
$sourceComputer = $tmp
} else {
Write-Host "No input entered, exiting"
Exit
}
Read-Host -Prompt "Destination Computer Name ($destinationComputer)" -OutVariable $tmp
if($tmp -ne ""){
$destinationComputer = $tmp
} else {
Write-Host "No input entered, exiting"
Exit
}
}
# Backup the source computer
Write-Host "Backing up $sourceComputer..."
Start-Process -Wait -NoNewWindow -FilePath "wbadmin" -ArgumentList "start backup -backupTarget:`"$backupLocation`" -include:`"C:`" -quiet"
# Restore to the destination computer
Write-Host "Restoring to $destinationComputer..."
Start-Process -Wait -NoNewWindow -FilePath "wbadmin" -ArgumentList "start recovery -backupTarget:`"$backupLocation`" -machineName:`"$destinationComputer`" -recoveryTarget:`"$restoreLocation`" -quiet"
# End message
Write-Host "Backup and restore completed successfully."