-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathBackupRestore.psm1
More file actions
60 lines (40 loc) · 1.4 KB
/
BackupRestore.psm1
File metadata and controls
60 lines (40 loc) · 1.4 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Function Backup-VMHost {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True)]
[string[]]$VMHost,
[Parameter(Mandatory=$True)]
[string]$FilePath
)
foreach($host in $VMHost){
Get-VMHostFirmware -VMHost $host -DestinationPath $FilePath -BackupConfiguration
Write-Host "Host $($host) backup completed." -foregroundcolor "magenta"
}
}
Function Restore-VMHost {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True)]
[string[]]$VMHost,
[Parameter(Mandatory=$True)]
[string]$FilePath,
[Parameter(Mandatory=$True)]
[string]$HostUsername,
[Parameter(Mandatory=$True)]
[string]$HostPassword
)
foreach($host in $VMHost){
Write-Host "$($host) is entering Maintenance Mode" -foregroundcolor "magenta"
Set-VMHost -VMHost $host -State "Maintenance"
#Assuming every ESXi host having same username & password
Set-VMHostFirmware -VMHost $host -SourcePath "$($FilePath)\configBundle-$($host).tgz" -Restore -HostUser $HostUsername -HostPassword $HostPassword
Write-Host "Host $($host) restore completed" -foregroundcolor "magenta"
}
#Adjust this wait time according to your environment
Write-Host "Waiting 3 minutes in order to allow every ESXi host to reboot" -foregroundcolor "magenta"
Start-sleep -s 180
foreach($host in $VMHost){
Write-Host "$($host) is exiting Maintenance Mode" -foregroundcolor "magenta"
Set-VMHost -VMHost $host -State "Connected"
}
}