diff --git a/buildlab.ps1 b/buildlab.ps1
index b2a552e..14aed64 100644
--- a/buildlab.ps1
+++ b/buildlab.ps1
@@ -16,14 +16,10 @@ param(
[parameter(mandatory=$true,ParameterSetName="VagrantUp")]
[string] $baseConfigName,
- [parameter(mandatory=$true,ParameterSetName="DownloadWSUS")] [switch] $DownloadWSUS,
- [parameter(mandatory=$true,ParameterSetName="ApplyWSUS")] [switch] $ApplyWSUS,
[parameter(mandatory=$true,ParameterSetName="BuildPacker")] [switch] $BuildPacker,
[parameter(mandatory=$true,ParameterSetName="AddToVagrant")] [switch] $AddToVagrant,
[parameter(mandatory=$true,ParameterSetName="VagrantUp")] [switch] $VagrantUp,
- [parameter(mandatory=$true,ParameterSetName="ApplyWSUS")] [string] $isoPath,
-
[string] $baseOutDir = "D:\iso\wintriallab",
[string] $tempDirOverride,
[string] $tag,
@@ -31,21 +27,9 @@ param(
[switch] $whatIf
)
-import-module dism -verbose:$false
-
-# Module useful for Download-URL at least. TODO: this mixes concerns and may not be ideal?
-get-module wintriallab-postinstall | remove-module
-import-module $PSScriptRoot\scripts\wintriallab-postinstall.psm1 -verbose:$false
-
+$errorActionPreference = "Stop"
Set-StrictMode -Version 2.0
-# This seems to be required with strict mode?
-$verbose = $true
-# This correctly covers -verbose -verbose:$false and -verbose:$true
-# if ($PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent -eq $true) {
-# $verbose = $true
-# }
-
$dateStamp = get-date -UFormat "%Y-%m-%d-%H-%M-%S"
$packerOutDir = "$baseOutDir\PackerOut"
$packerCacheDir = "$baseOutDir\packer_cache"
@@ -59,7 +43,6 @@ $wimMountDir = "${labTempDir}\MountInstallWim"
$installMediaTemp = "${labTempDir}\InstallMedia"
$newMediaIsoPath = "${labTempDir}\windows.iso"
-$errorActionPreference = "Stop"
$fullConfigName = "wintriallab-${baseConfigName}"
set-alias packer (gcm packer | select -expand path)
@@ -69,98 +52,11 @@ set-alias vagrant (gcm vagrant | select -expand path)
$outDir = "${packerOutDir}\${fullConfigName}"
if ($tag) { $outDir += "-${tag}"}
-$packerConfigRoot = "${PSScriptRoot}\${baseConfigName}"
+$packerConfigRoot = "${PSScriptRoot}\packer\${baseConfigName}"
$packerFile = "${packerConfigRoot}\${baseConfigName}.packerfile.json"
$packedBoxPath = "${outDir}\${baseConfigName}_virtualbox.box"
$vagrantTemplate = "${packerConfigRoot}\vagrantfile-${baseConfigName}.template"
-function Download-WSUSOfflineUpdater {
- if (test-path $wsusOfflineDir) {
- throw "WSUSOffline is already extracted to '$wsusOfflineDir'"
- }
- $filename = "wsusoffline101.zip"
- $url = "http://download.wsusoffline.net/$filename"
- $dlPath = "$labTempDir\$filename"
- Get-WebUrl -url $url -downloadPath $dlPath
- $exDir = resolve-path "$wsusOfflineDir\.." # why the ".." ? because the zipfile puts everything in a 'wsusoffline' folder
- sevenzip x "$dlPath" "-o$exDir"
-}
-function Download-WindowsUpdates {
- set-alias DownloadUpdates "$wsusOfflineDir\cmd\DownloadUpdates.cmd"
- foreach ($product in @('w63','w63-x64','w100','w100-x64')) {
- DownloadUpdates $product glb /includedotnet /verify
- }
-}
-
-<#
-.notes
-The install.wim file doesn't (ever? sometimes?) denote architecture in its image names, but boot.wim (always? usually?) does
-#>
-function Get-BootWimArchitecture {
- [cmdletbinding()] param(
- [parameter(mandatory=$true)] $wimFile
- )
- $bootWimInfo = Get-WindowsImage -imagePath $wimFile -verbose:$verbose
-
- $arch = $null
- if (-not $bootWimInfo) { throw "Got no information for wimfile at '$wimFile'"}
- elseif ($bootWimInfo[0].ImageName -match "x86") { $arch = $ArchitectureId.i386 }
- elseif ($bootWimInfo[0].ImageName -match "x64") { $arch = $ArchitectureId.amd64 }
- else { throw "Could not determine architecture for '$wimFile'"}
-
- write-verbose "Found an architecture of '$arch' for '$wimFile'"
- return $arch
-}
-
-
-function Apply-WindowsUpdatesToIso {
- [cmdletbinding()] param (
- [parameter(mandatory=$true)] [string] $inputIso,
- [parameter(mandatory=$true)] [string] $outputIso,
- [parameter(mandatory=$true)] [string] $wsusOfflineDir,
- [parameter(mandatory=$true)] [string] $wimMountDir
- )
-
- $myWimMounts = @()
-
- mount-diskimage -imagepath $inputIso
- $mountedDrive = get-diskimage -imagepath $inputIso | get-volume | select -expand DriveLetter
-
- $installWim = "$labTempDir\install.wim"
- if (-not (test-path $installWim)) {
- cp "${mountedDrive}:\Sources\install.wim" $labTempDir -verbose:$verbose
- }
- else {
- write-verbose "Using EXISTING install.wim at '$installWim'"
- }
- Set-ItemProperty -path $installWim -name IsReadOnly -value $false -force
-
- $arch = Get-BootWimArchitecture -wimFile "${mountedDrive}:\sources\boot.wim" -verbose:$verbose
- dismount-diskimage -imagepath $inputIso
-
- $wimInfo = Get-WindowsImage -imagePath $installWim
- $shortCode = Get-WOShortCode -OSName $wimInfo[0].ImageName -OSArchitecture $arch
- #$updatePath = resolve-path "${wsusOfflineDir}\client\$shortCode\glb" | select -expand Path
- $updatePath = "D:\iso\wintriallab\temp-slipstream\WSUSCache\w63-i386-glb"
-
- foreach ($wimInfo in (Get-WindowsImage -imagePath $installWim)) {
- $wimMountSubdir = mkdir "${wimMountDir}\$($wimInfo.ImageIndex)" -force | select -expand fullname
- Mount-WindowsImage -imagePath $installWim -index $wimInfo.ImageIndex -path $wimMountSubdir
-
- write-verbose "Applying '$((ls $updatePath).count)' updates to '$wimInfo'''"
- try {
- Add-WindowsPackage -PackagePath $updatePath -path $wimMountSubdir
- }
- catch {
- write-verbose "Caught error(s) when installing packages:`n`n$_`n"
- }
-
- Dismount-WindowsImage -Path $wimMountSubdir -Save
- }
-
- New-WindowsInstallMedia -sourceIsoPath $inputIso -installMediaTemp $installMediaTemp -installWimPath $installWim -outputIsoPath $outputIso
-}
-
function Build-PackerFile {
[cmdletbinding()]
param(
@@ -199,10 +95,10 @@ function Build-PackerFile {
popd
}
$outBox = get-item $outDir\*.box
- if ($outBox.count -gt 1) {
+ if ($outBox.PSObject.Properties['count'] -and $outBox.count -gt 1) {
throw "Somehow you came up with more than one box here: '$outBox'"
}
- if ($outBox -notmatch [Regex]::Escape($packedBoxPath)) {
+ if ($outBox.fullname -notmatch [Regex]::Escape($packedBoxPath)) {
throw "Found an output box '$outBox', but it doesn't match the expected packed box path of '$packedBoxPath'"
}
cp "$vagrantTemplate" "$outDir\Vagrantfile"
@@ -279,15 +175,6 @@ if ($baseConfigName) {
write-output ""
}
-if ($DownloadWSUS) {
- if (-not (test-path $wsusOfflineDir)) {
- Download-WSUSOfflineUpdater
- }
- Download-WindowsUpdates
-}
-if ($ApplyWSUS) {
- Apply-WindowsUpdatesToIso -inputIso $isoPath -outputIso $newMediaIsoPath -wsusOfflineDir $wsusOfflineDir -wimMountDir $wimMountDir -verbose:$verbose
-}
if ($BuildPacker) {
$bpfParam = @{
packerFile = $packerFile
diff --git a/packer/windows_10_x86/Autounattend.xml b/packer/windows_10_x86/Autounattend.xml
new file mode 100644
index 0000000..0dac836
--- /dev/null
+++ b/packer/windows_10_x86/Autounattend.xml
@@ -0,0 +1,154 @@
+
+
+
+
+
+
+
+
+
+ 1
+ Primary
+ true
+
+
+
+
+ false
+ NTFS
+ C
+ 1
+ 1
+
+
+
+ 0
+ true
+
+ OnError
+
+
+ true
+
+
+
+
+ NPPR9-FWDCX-D2C8J-H872K-2YT43
+ Never
+
+
+
+
+
+ 0
+ 1
+
+ OnError
+ false
+
+
+ /IMAGE/NAME
+ Windows 10 Enterprise Evaluation
+
+
+
+
+
+
+
+ en-US
+
+ en-US
+ en-US
+ en-US
+ en-US
+ en-US
+
+
+
+
+ false
+
+
+
+
+
+
+ V@grant123
+ true
+
+
+
+
+ V@grant123
+ true
+
+ Vagrant User
+ vagrant
+ administrators
+ vagrant
+
+
+
+
+ true
+ true
+ Home
+ 1
+
+
+
+ V@grant123
+ true
+
+ vagrant
+ true
+
+
+
+
+ cmd.exe /c powershell -ExecutionPolicy Unrestricted -Command "Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Force"
+ Set Execution Policy
+ 1
+ true
+
+
+
+
+ powershell.exe -File A:\autounattend-postinstall.ps1
+ Run Postinstall Script
+ 99
+ true
+
+
+
+ false
+
+
+
+
+
+ false
+
+
+ vagrant-10-x86
+ Central Standard Time
+
+
+
+ true
+
+
+
+
diff --git a/packer/windows_10_x86/vagrantfile-windows_10_x86.template b/packer/windows_10_x86/vagrantfile-windows_10_x86.template
new file mode 100644
index 0000000..6631343
--- /dev/null
+++ b/packer/windows_10_x86/vagrantfile-windows_10_x86.template
@@ -0,0 +1,27 @@
+# -*- mode: ruby -*-
+# vi: set ft=ruby :
+
+Vagrant.require_version ">= 1.6.2"
+
+Vagrant.configure("2") do |config|
+ config.vm.define "vagrant-windows-10"
+ config.vm.box = "windows_10"
+ config.vm.communicator = "winrm"
+
+ # Admin user name and password
+ config.winrm.username = "vagrant"
+ config.winrm.password = "V@grant123"
+
+ config.vm.guest = :windows
+ config.windows.halt_timeout = 15
+
+ config.vm.network :forwarded_port, guest: 3389, host: 3389, id: "rdp", auto_correct: true
+
+ config.vm.provider :virtualbox do |v, override|
+ #v.gui = true
+ v.customize ["modifyvm", :id, "--memory", 1024]
+ v.customize ["modifyvm", :id, "--cpus", 1]
+ v.customize ["setextradata", "global", "GUI/SuppressMessages", "all" ]
+ end
+
+end
diff --git a/packer/windows_10_x86/windows_10_x86.packerfile.json b/packer/windows_10_x86/windows_10_x86.packerfile.json
new file mode 100644
index 0000000..2d0df3c
--- /dev/null
+++ b/packer/windows_10_x86/windows_10_x86.packerfile.json
@@ -0,0 +1,54 @@
+{
+ "variables": {
+ "output_directory": "packer-output"
+ },
+ "builders": [
+ {
+ "type": "virtualbox-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",
+ "headless": true,
+ "boot_wait": "2m",
+ "communicator": "winrm",
+ "winrm_username": "vagrant",
+ "winrm_password": "V@grant123",
+ "winrm_timeout": "72h",
+ "shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"",
+ "guest_os_type": "Windows10",
+ "disk_size": 61440,
+ "guest_additions_mode": "attach",
+ "floppy_files": [
+ "./Autounattend.xml",
+ "../../scripts/win-updates.ps1",
+ "../../scripts/enable-winrm.ps1",
+ "../../scripts/wintriallab-postinstall.psm1",
+ "../../scripts/autounattend-postinstall.ps1",
+ "../../scripts/provisioner-postinstall.ps1"
+ ],
+ "vboxmanage": [
+ ["setextradata", "global", "GUI/SuppressMessages", "all" ],
+ ["modifyvm", "{{.Name}}", "--memory", "2048" ],
+ ["modifyvm", "{{.Name}}", "--cpus", "2" ],
+ ["modifyvm", "{{.Name}}", "--accelerate2dvideo", "on"],
+ ["modifyvm", "{{.Name}}", "--vram", 128]
+ ]
+ }
+ ],
+ "provisioners": [
+
+ {
+ "type": "powershell",
+ "inline": ["A:\\provisioner-postinstall.ps1 -Verbose"]
+ }
+
+ ],
+ "post-processors": [
+ {
+ "type": "vagrant",
+ "keep_input_artifact": false,
+ "output": "{{user `output_directory`}}/windows_10_x86_{{.Provider}}.box",
+ "vagrantfile_template": "vagrantfile-windows_10_x86.template"
+ }
+ ]
+}
diff --git a/windows_81_x86/Autounattend.xml b/packer/windows_81_x86/Autounattend.xml
similarity index 96%
rename from windows_81_x86/Autounattend.xml
rename to packer/windows_81_x86/Autounattend.xml
index 344d39c..5e453e7 100644
--- a/windows_81_x86/Autounattend.xml
+++ b/packer/windows_81_x86/Autounattend.xml
@@ -29,14 +29,8 @@
true
-
-
-