-
Notifications
You must be signed in to change notification settings - Fork 60
/
build-hyperv.ps1
74 lines (60 loc) · 1.95 KB
/
build-hyperv.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/local/bin/pwsh
#Requires -RunAsAdministrator
param(
[switch]$offline,
[switch]$SkipPester,
[switch]$ServerOnly,
[switch]$TentacleOnly,
[string]$OctopusVersion,
[switch]$retainondestroy,
[switch]$debug
)
. Tests/powershell-helpers.ps1
Start-Transcript .\vagrant-hyperv.log
Set-OctopusDscEnvVars @PSBoundParameters
# remove psreadline as it interferes with the SMB password prompt
if(Get-Module PSReadLine) {
Remove-Module PSReadLine
}
if (-not (Test-AppExists "vagrant")) {
Write-Output "Please install vagrant from vagrantup.com."
exit 1
}
Write-Output "Vagrant installed - good."
if ((Get-CimInstance Win32_OperatingSystem).PRODUCTTYPE -eq 1) {
# client OS detected
if ((Get-WindowsOptionalFeature -Online -FeatureName 'Microsoft-Hyper-V').State -eq 'Disabled') {
Write-Output 'Please install Hyper-V.'
exit 1
}
}
else {
# server OS detected
if ((Get-WindowsFeature 'Hyper-V').State -eq 'Disabled') {
Write-Output 'Please install Hyper-V.'
exit 1
}
}
Write-Output "Hyper-V installed - good."
if (-not (Get-VMSwitch -Name $env:OctopusDSCVMSwitch -ErrorAction SilentlyContinue)) {
Write-Output "Could not find a Hyper-V switch called $($env:OctopusDSCVMSwitch)"
exit 1
}
Write-Output (@("Hyper-V virtual switch '", $env:OctopusDSCVMSwitch, "' detected - good.") -join "")
Test-CustomVersionOfVagrantDscPluginIsInstalled
Test-PluginInstalled "vagrant-winrm-syncedfolders"
Test-PluginInstalled "vagrant-winrm-file-download"
Remove-OldLogsBeforeNewRun
if(-not $SkipPester) {
Invoke-PesterTests
} else {
Write-Output "-SkipPester was specified, skipping pester tests"
}
$splat = @{
provider="hyperv";
retainondestroy = $retainondestroy.IsPresent; # set to $true to override in this script
debug = $debug.IsPresent; # set to $true to override in this script
}
Invoke-VagrantWithRetries @splat
Write-Output "Don't forget to run 'vagrant destroy -f' when you have finished"
stop-transcript