Initial Hyper-V support, some bugfixes

jowjDev
Micah R Ledbetter 7 years ago
parent 66de58d20a
commit f0678fbd5e

@ -40,6 +40,30 @@
["modifyvm", "{{.Name}}", "--accelerate2dvideo", "on"],
["modifyvm", "{{.Name}}", "--vram", 128]
]
},
{
"type": "hyperv-iso",
"iso_url": "http://care.dlservice.microsoft.com/dl/download/C/3/9/C399EEA8-135D-4207-92C9-6AAB3259F6EF/10240.16384.150709-1700.TH1_CLIENTENTERPRISEEVAL_OEMRET_X86FRE_EN-US.ISO",
"iso_checksum_type": "sha1",
"iso_checksum": "875b450d67e7176b8b3c72a80c60a0628bf1afac",
"boot_wait": "2m",
"communicator": "winrm",
"winrm_username": "vagrant",
"winrm_password": "V@grant123",
"winrm_timeout": "24h",
"shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"",
"disk_size": 61440,
"enable_virtualization_extensions": true,
"ram_size": 2048,
"cpu": 2,
"floppy_files": [
"./Autounattend.xml",
"../../scripts/win-updates.ps1",
"../../scripts/enable-winrm.ps1",
"../../scripts/wintriallab-postinstall.psm1",
"../../scripts/autounattend-postinstall.ps1",
"../../scripts/provisioner-postinstall.ps1"
]
}
],
"provisioners": [

@ -1,11 +1,17 @@
[cmdletbinding(DefaultParameterSetName="RunWindowsUpdates")] param(
[Parameter(ParameterSetName="RunWindowsUpdates")] [switch] $RunWindowsUpdates,
[Parameter(Mandatory=$true,ParameterSetName="SkipWindowsUpdates")] [switch] $SkipWindowsUpdates
[cmdletbinding()] Param(
[switch] $SkipWindowsUpdates
)
import-module $PSScriptRoot\wintriallab-postinstall.psm1
$errorActionPreference = "Stop"
# Useful for debugging
$message = "Environment variables: `r`n`r`n"
foreach ($var in (Get-ChildItem env:\)) {
$message += "$($var.Name) = $($var.Value)`r`n"
}
Write-EventLogWrapper -message $message
Invoke-ScriptblockAndCatch -scriptBlock {
Write-EventLogWrapper "Starting the autounattend postinstall script"
Set-IdleDisplayPoweroffTime -seconds 0
@ -13,21 +19,30 @@ Invoke-ScriptblockAndCatch -scriptBlock {
Disable-HibernationFile
Enable-MicrosoftUpdate
# Need to reboot for some of these drivers to take
# Requires that the packer file attach the Guest VM driver disc, rather than upload it
# (Uploading it also gives problems when using WinRM - too big? - so this is a better solution anyway)
Install-VBoxAdditions -fromDisc
# Note that we need to reboot for some of these drivers to take
# AHHHH, PACKER_BUILDER_TYPE ISN'T AVAILABLE HERE BECAUSE IT'S INVOKED FROM THE WINDOWS INSTALLER. Hmmmmmm. Might have to do this later.
if ($env:PACKER_BUILDER_TYPE -contains "virtualbox") {
# Requires that the packerfile attach the Guest VM driver disk, rather than upload it (the packer-windows way). Uploading it gives problems with WinRM for some reason.
Install-VBoxAdditions -fromDisc
}
elseif ($env:PACKER_BUILDER_TYPE -contains "hyperv") {
Write-EventLogWrapper -message "Hyper-V builder detected, but we don't have a way to install its drivers yet"
}
else {
Write-EventLogWrapper -message "A builder called '$env:PACKER_BUILDER_TYPE' was detected, but we don't have a way to install its drivers yet"
}
# Required for Windows 10, not required for 81, not sure about other OSes
# Should probably happen after installing Guest VM drivers, in case installing the drivers would cause Windows to see the network as a new connection
Set-AllNetworksToPrivate
# Should probably happen after installing Guest VM drivers, in case installing the drivers would cause Windows to see the network as a new connection
Set-AllNetworksToPrivate
switch ($PsCmdlet.ParameterSetName) {
"RunWindowsUpdates" { $restartCommand = [ScriptBlock]::Create("A:\win-updates.ps1 -PostUpdateExpression A:\enable-winrm.ps1") }
"SkipWindowsUpdates" { $restartCommand = [ScriptBlock]::Create("A:\enable-winrm.ps1") }
default { throw "Not configured for this parameter set..." }
if ($SkipWindowsUpdates) {
$restartCommand = [ScriptBlock]::Create("A:\enable-winrm.ps1") }
}
else {
$restartCommand = [ScriptBlock]::Create("A:\win-updates.ps1 -PostUpdateExpression A:\enable-winrm.ps1")
}
Set-RestartScheduledTask -RestartCommand $restartCommand | out-null
Restart-Computer -force
Restart-Computer -force
}

@ -10,13 +10,13 @@ $errorActionPreference = "Continue"
import-module $PSScriptRoot\wintriallab-postinstall.psm1
# These commands are fragile and shouldn't fail the build if they fail, so I put them in a try/catch outside of Invoke-ScriptblockAndCatch
try {
try {
Set-PinnedApplication -Action UnpinFromTaskbar -Filepath "C:\Program Files\WindowsApps\Microsoft.WindowsStore_2015.10.5.0_x86__8wekyb3d8bbwe\WinStore.Mobile.exe" -ErrorAction Continue
Set-PinnedApplication -Action PinToTaskbar -Filepath "$PSHOME\Powershell.exe"
Set-PinnedApplication -Action PinToTaskbar -Filepath "${env:SystemRoot}\system32\eventvwr.msc"
$UserPinnedTaskBar = "${env:AppData}\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar"
if (test-path "$UserPinnedTaskBar\Server Manager.lnk") { rm "$UserPinnedTaskBar\Server Manager.lnk" }
}
}
catch {}
Invoke-ScriptblockAndCatch -scriptBlock {

@ -1134,7 +1134,7 @@ function Set-IdleDisplayPoweroffTime {
.description
Allow connecting to HTTPS WinRM servers (used with, for example, Enter-PSSession) without checking the certificate. This is not recommended, but can be useful for non-domain-joined VMs that will connect to a remote network over a VPN. (Note that not checking the RDP certificate is no improvement over not checking the WinRM certificate.)
#>
Enable-UntrustedOutboundWinRmConnections {
function Enable-UntrustedOutboundWinRmConnections {
[CmdletBinding()] Param()
Set-Item WSMan:\localhost\Client\Auth\CredSSP $True
Set-Item WSMan:\localhost\Service\Auth\CredSSP $True

Loading…
Cancel
Save