forked from winfsp/winfsp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.ps1
35 lines (30 loc) · 1.09 KB
/
deploy.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
param (
[Parameter(Mandatory)][string]$Name,
[string]$CheckpointName,
[Parameter(Mandatory)][string[]]$Files,
[Parameter(Mandatory)][string]$Destination
)
function Restore-VM ($Name, $CheckpointName) {
$VM = Get-VM -Name $Name
if ($VM.State -eq "Running") {
Stop-VM -Name $Name -TurnOff
}
if (-not $CheckpointName) {
$Checkpoint = Get-VMCheckpoint -VMName $Name |
Sort-Object -Property CreationTime -Descending |
select -First 1
} else {
$Checkpoint = Get-VMCheckpoint -VMName $Name -Name $CheckpointName
}
Restore-VMCheckpoint -VMCheckpoint $Checkpoint -Confirm:$false
Start-VM -Name $Name
}
function Deploy-VMFiles ($Name, $Files, $Destination) {
foreach ($File in $Files) {
$Leaf = Split-Path -Path $File -Leaf
$Dest = Join-Path $Destination $Leaf
Copy-VMFile -Name $Name -SourcePath $File -DestinationPath $Dest -FileSource Host -CreateFullPath -Force
}
}
Restore-VM -Name $Name -CheckpointName $CheckpointName
Deploy-VMFiles -Name $Name -Files $Files -Destination $Destination