├── .gitignore
├── README.md
├── firstboot.ps1
├── provision.ps1
├── windows10
├── Autounattend.xml
├── packer.json
└── vagrantfile.template
├── windows1803
├── Autounattend.xml
├── packer.json
└── vagrantfile.template
├── windows2016
├── Autounattend.xml
├── packer.json
└── vagrantfile.template
├── windows2019
├── Autounattend.xml
├── packer.json
└── vagrantfile.template
└── winrm.ps1
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | /output-vmware/
3 | /output-vmware-iso/
4 | /output-vmware-vmx/
5 | /output-virtualbox/
6 | /output-virtualbox-iso/
7 | /output-virtualbox-ovf/
8 | /*.box
9 | /packer_cache/
10 | variables.json
11 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Windows Packer Templates
2 |
3 | Simple [Packer](https://packer.io) templates for creating Windows VMs that support mainstream use cases that can easily be forked and built upon.
4 |
5 | This project makes use of [reusable PowerShell modules](https://github.com/windowsbox/powershellmodules) which allow for others to easily create their own Packer templates without needing to fork a bunch of scripts. Packer templates tend to vary between people and companies but the scripts used by the templates don't vary as much. This is an attempt to separate out the reusable parts from the parts that don't.
6 |
7 | ## Building a Box
8 |
9 | 1. Clone this repository
10 | 2. Install [Packer](http://packer.io) 1.3.4 or newer
11 | 3. Execute Packer (see below)
12 |
13 | You may need to set the `iso_url` and `iso_checksum` variables as some builds expect you to have downloaded an ISO from MSDN and have no default set. A good way to handle this is to use a Packer vars file. You may also need to set the product key code in the Autounattend.xml file depending on the OS installation media chosen.
14 |
15 | The Windows templates support a plain vanilla Windows Vagrant box or a Windows Vagrant box with a bunch of .NET development tools. The examples below are shown without installing the dev tools.
16 |
17 | ### Windows10
18 |
19 | The plain vanilla build creates a Windows 10 box with Windows updates and not much else.
20 | ```
21 | $ packer build windows10/packer.json
22 | ```
23 |
24 | ### Windows Server 2016
25 |
26 | The plain vanilla build creates a Windows Server 2016 box with Windows updates and not much else other than Docker.
27 | ```
28 | $ packer build windows2016/packer.json
29 | ```
30 |
31 | ### Windows Server 1803
32 |
33 | The plain vanilla build creates a Windows Server 1803 box with Windows updates and not much else other than Docker.
34 | ```
35 | $ packer build windows1803/packer.json
36 | ```
37 |
38 | ### Windows Server 2019
39 |
40 | The plain vanilla build creates a Windows Server 2019 box with Windows updates and not much else other than Docker.
41 | ```
42 | $ packer build windows2019/packer.json
43 | ```
44 |
45 | ### Development Tools Installation
46 |
47 | The .NET developer Vagrant box includes everything the vanilla box includes plus the following tools:
48 | - Powershell Packagemanagement
49 | - Visual Studio 2017 Community Edition
50 | - Resharper 2017
51 | - Notepad++
52 | - Google Chrome
53 | - Git for Windows
54 | - Beyond Compare
55 | - Fiddler 4
56 | - SoapUI
57 | - Sql Server Management Studio
58 | - Node JS
59 | - CloudFoundry CLI
60 | - Nuget CLI
61 |
62 | If you want the development tools add `-var devtools=true` to your Packer command line, for example:
63 | ```
64 | $ packer build -var devtools=true windows10/packer.json
65 | ```
66 |
67 | ## Development
68 |
69 | ### Local ISOs
70 |
71 | You may want to use a Windows ISO already downloaded because you cleared your Packer cache or for other reasons. The simplest way to use an already existing ISO on your HDD is to serve it up via Python. From the directory where the ISO exists run: `python -m SimpleHTTPServer`. Then override the `iso_url` and `iso_checksum` variables by creating a variables.json file.
72 |
73 | ```
74 | {
75 | "iso_url": "http://10.0.0.207:8000/en_windows_10_multi-edition_vl_version_1709_updated_dec_2017_x64_dvd_100406172.iso",
76 | "iso_checksum": "f38b0aeae0756e01dcd9b1600de62416e04aa963c72cea30929141f54f1235b3"
77 | }
78 |
79 | ```
80 |
81 | ```
82 | $ packer build -var-file windows10/variables.json windows10/packer.json
83 | ```
84 |
85 | ### Local PowerShell Module Testing
86 |
87 | You may want to test a WindowsBox PowerShell Modules change before committing and publishing it. The quickest way to do that is to make the necessary script changes and then provide the script to the guest VM through the `a:\` drive. Mount the locally modified script by modifying the packer.json and add a floppy files entry, for example:
88 |
89 | ```
90 | "floppy_files": [
91 | "../powershellmodules/modules/WindowsBox.WinRM/WindowsBox.WinRM.psm1",
92 | ...
93 | ```
94 |
95 | Then you need to temporarily change how that module is loaded, from:
96 | ```
97 | Install-Module WindowsBox.WinRM -Force
98 | ```
99 | to
100 | ```
101 | Import-Module -Name a:\WindowsBox.WinRM.psm1 -DisableNameChecking -Force
102 | ```
103 |
104 | ## Thanks
105 |
106 | This project would not be possible without a lot of work from other projects like [Packer-Windows](https://github.com/joefitzgerald/packer-windows).
107 |
108 | ## Project Values
109 |
110 | - Modern OSs and tools
111 | - Simplicity
112 | - Reuse
113 |
--------------------------------------------------------------------------------
/firstboot.ps1:
--------------------------------------------------------------------------------
1 | # Runs before Packer provisioners during first boot
2 |
3 | # We explicitly install nuget because install-module prompts for confirmation even with -Force
4 | Install-PackageProvider -Name Nuget -Force
5 |
6 | # Configure the network to private so we can properly configure WinRM
7 | Install-Module WindowsBox.Network -Force
8 | Set-NetworkToPrivate
9 |
10 | # Kick off the WinRM script that polls for updates to be complete
11 | Start-Job -ScriptBlock { C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -ExecutionPolicy Bypass -File a:\winrm.ps1 }
12 |
13 | # Install all available Windows updates
14 | Install-Module WindowsBox.WindowsUpdates -Force
15 | Install-WindowsUpdates
16 |
--------------------------------------------------------------------------------
/provision.ps1:
--------------------------------------------------------------------------------
1 | # Runs after Windows Updates have been applied
2 |
3 | Install-Module WindowsBox.AutoLogon -Force
4 | Install-Module WindowsBox.Compact -Force
5 | Install-Module WindowsBox.Explorer -Force
6 | Install-Module WindowsBox.Hibernation -Force
7 | Install-Module WindowsBox.RDP -Force
8 | Install-Module WindowsBox.UAC -Force
9 | Install-Module WindowsBox.VagrantAccount -Force
10 | Install-Module WindowsBox.VMGuestTools -Force
11 |
12 | Disable-AutoLogon
13 | Disable-UAC
14 | Enable-RDP
15 | Set-ExplorerConfiguration
16 | Disable-Hibernation
17 | Set-VagrantAccount
18 | Install-VMGuestTools
19 |
20 | # Install Docker if the provider is available on this OS
21 | Install-Module DockerMsftProvider -Force
22 | if ((Get-PackageProvider -ListAvailable).Name -Contains "DockerMsftProvider") {
23 | Install-Package -Name docker -ProviderName DockerMsftProvider -Force
24 | }
25 |
26 | if ($env:devtools -eq $true) {
27 | # Install Linux subsystem
28 | Install-Module WindowsBox.DevMode -Force
29 | Enable-DevMode
30 |
31 | # Install chocolatey and use it to install dev tools
32 | Invoke-WebRequest https://chocolatey.org/install.ps1 -UseBasicParsing | Invoke-Expression
33 |
34 | choco install powershell-packagemanagement -y
35 | choco install visualstudio2019community -y
36 | choco install visualstudio2019-workload-netcoretools -y
37 | choco install visualstudio2019-workload-netweb -y
38 | choco install visualstudio2019-workload-node -y
39 | choco install visualstudio2019-workload-azure -y
40 | choco install visualstudio2019-workload-nativedesktop -y
41 | choco install visualstudio2019-workload-manageddesktop -y
42 | choco install resharper -y
43 | choco install notepadplusplus.install -y
44 | choco install googlechrome -y
45 | choco install git.install -y
46 | choco install beyondcompare -y
47 | choco install fiddler4 -y
48 | choco install sql-server-management-studio -y
49 | choco install nodejs.install -y
50 | choco install cloudfoundry-cli -y
51 | choco install nuget.commandline -y
52 | choco install soapui -y
53 | }
54 |
55 | # Final cleanup
56 | Optimize-DiskUsage
57 |
--------------------------------------------------------------------------------
/windows10/Autounattend.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | vagrant-win10
6 | Microsoft
7 | Pacific Standard Time
8 |
9 |
10 | true
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | 0
19 | 1
20 |
21 |
22 |
23 | /IMAGE/INDEX
24 | 1
25 |
26 |
27 | OnError
28 | false
29 |
30 |
31 |
32 | true
33 | Vagrant Administrator
34 | Vagrant Inc.
35 |
36 |
37 |
38 |
39 |
40 | 1
41 | Primary
42 | true
43 |
44 |
45 |
46 |
47 | true
48 | false
49 | NTFS
50 |
51 | C
52 | 1
53 | 1
54 |
55 |
56 | 0
57 | true
58 |
59 | OnError
60 |
61 |
62 |
63 | en-US
64 | en-US
65 | en-US
66 | en-US
67 |
68 |
69 |
70 |
71 | en-US
72 | en-US
73 | en-US
74 | en-US
75 | en-US
76 |
77 |
78 |
79 |
80 |
81 |
82 | dgBhAGcAcgBhAG4AdABQAGEAcwBzAHcAbwByAGQA
83 | false
84 |
85 | Vagrant User
86 | vagrant
87 | Administrators
88 | vagrant
89 |
90 |
91 |
92 |
93 |
94 | dgBhAGcAcgBhAG4AdABQAGEAcwBzAHcAbwByAGQA
95 | false
96 |
97 | true
98 | vagrant
99 |
100 |
101 | 1
102 |
103 |
104 |
105 | powershell -NoLogo -ExecutionPolicy RemoteSigned -File a:\firstboot.ps1
106 | Start WinRM
107 | 1
108 |
109 |
110 |
111 |
112 |
113 |
114 | false
115 |
116 |
117 |
118 |
119 |
--------------------------------------------------------------------------------
/windows10/packer.json:
--------------------------------------------------------------------------------
1 | {
2 | "variables": {
3 | "iso_url": "https://software-download.microsoft.com/download/sg/17763.107.101029-1455.rs5_release_svc_refresh_CLIENTENTERPRISEEVAL_OEMRET_x64FRE_en-us.iso",
4 | "iso_checksum": "0278fc4638741f4a1dc85c39ed7fa76bb15fd582165f6ef036e9a9fb2f029351",
5 | "headless": "true",
6 | "devtools": "false"
7 | },
8 | "builders": [
9 | {
10 | "type": "virtualbox-iso",
11 | "communicator": "winrm",
12 | "disk_size": 61440,
13 | "floppy_files": [
14 | "windows10/Autounattend.xml",
15 | "firstboot.ps1",
16 | "winrm.ps1"
17 | ],
18 | "guest_os_type": "Windows10_64",
19 | "headless": "{{user `headless`}}",
20 | "iso_url": "{{user `iso_url`}}",
21 | "iso_checksum_type": "sha256",
22 | "iso_checksum": "{{user `iso_checksum`}}",
23 | "winrm_username": "vagrant",
24 | "winrm_password": "vagrant",
25 | "winrm_timeout": "3h",
26 | "shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"",
27 | "post_shutdown_delay": "30s",
28 | "guest_additions_mode": "attach",
29 | "vboxmanage": [
30 | [
31 | "modifyvm",
32 | "{{.Name}}",
33 | "--memory",
34 | "4096"
35 | ],
36 | [
37 | "modifyvm",
38 | "{{.Name}}",
39 | "--cpus",
40 | "2"
41 | ],
42 | [
43 | "modifyvm",
44 | "{{.Name}}",
45 | "--vram",
46 | "32"
47 | ]
48 | ]
49 | }
50 | ],
51 | "provisioners": [
52 | {
53 | "type": "powershell",
54 | "scripts": ["provision.ps1"],
55 | "environment_vars": ["devtools={{user `devtools`}}"]
56 | },
57 | {
58 | "type": "windows-restart",
59 | "restart_timeout": "10m"
60 | }
61 | ],
62 | "post-processors": [
63 | {
64 | "type": "vagrant",
65 | "output": "{{.Provider}}_windows10.box",
66 | "vagrantfile_template": "windows10/vagrantfile.template"
67 | }
68 | ]
69 | }
70 |
--------------------------------------------------------------------------------
/windows10/vagrantfile.template:
--------------------------------------------------------------------------------
1 | # -*- mode: ruby -*-
2 | # vi: set ft=ruby :
3 |
4 | Vagrant.require_version ">= 1.6.2"
5 |
6 | Vagrant.configure("2") do |config|
7 | config.vm.box = "windows10"
8 | config.vm.communicator = "winrm"
9 | config.vm.provider "virtualbox" do |v, override|
10 | v.customize ["setextradata", "global", "GUI/SuppressMessages", "all" ]
11 | end
12 | end
13 |
--------------------------------------------------------------------------------
/windows1803/Autounattend.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | vagrant-win1803
6 | Microsoft
7 | Pacific Standard Time
8 |
9 |
10 | true
11 |
12 |
13 | true
14 |
15 |
16 | false
17 | false
18 |
19 |
20 |
21 |
22 | true
23 | Google
24 | Google
25 | http://www.google.com/search?q={searchTerms}
26 |
27 |
28 | true
29 | true
30 | about:blank
31 |
32 |
33 | false
34 |
35 |
36 | 0
37 |
38 |
39 |
40 |
41 | true
42 | Remote Desktop
43 | all
44 |
45 |
46 |
47 |
48 | true
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 | 0
57 | 1
58 |
59 |
60 |
61 | /IMAGE/INDEX
62 | 1
63 |
64 |
65 | OnError
66 | false
67 |
68 |
69 |
70 | true
71 | Vagrant Administrator
72 | Vagrant Inc.
73 |
74 |
75 |
76 |
77 |
78 | 1
79 | Primary
80 | true
81 |
82 |
83 |
84 |
85 | true
86 | false
87 | NTFS
88 |
89 | C
90 | 1
91 | 1
92 |
93 |
94 | 0
95 | true
96 |
97 | OnError
98 |
99 |
100 |
101 | en-US
102 | en-US
103 | en-US
104 | en-US
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 | dgBhAGcAcgBhAG4AdABQAGEAcwBzAHcAbwByAGQA
114 | false
115 |
116 | Vagrant User
117 | vagrant
118 | Administrators
119 | vagrant
120 |
121 |
122 |
123 |
124 |
125 | dgBhAGcAcgBhAG4AdABQAGEAcwBzAHcAbwByAGQA
126 | false
127 |
128 | true
129 | vagrant
130 |
131 |
132 | true
133 | true
134 | true
135 | true
136 | true
137 | Home
138 |
144 | 3
145 |
146 |
147 |
148 | powershell -NoLogo -ExecutionPolicy RemoteSigned -File a:\firstboot.ps1
149 | Start WinRM
150 | 1
151 |
152 |
153 |
154 |
155 |
156 |
157 | false
158 |
159 |
160 |
161 |
162 |
--------------------------------------------------------------------------------
/windows1803/packer.json:
--------------------------------------------------------------------------------
1 | {
2 | "variables": {
3 | "iso_url": "",
4 | "iso_checksum": "",
5 | "headless": "true",
6 | "devtools": "false"
7 | },
8 | "builders": [
9 | {
10 | "type": "virtualbox-iso",
11 | "communicator": "winrm",
12 | "disk_size": 61440,
13 | "floppy_files": [
14 | "windows1803/Autounattend.xml",
15 | "firstboot.ps1",
16 | "winrm.ps1"
17 | ],
18 | "guest_os_type": "Windows2016_64",
19 | "headless": "{{user `headless`}}",
20 | "iso_url": "{{user `iso_url`}}",
21 | "iso_checksum_type": "sha256",
22 | "iso_checksum": "{{user `iso_checksum`}}",
23 | "winrm_username": "vagrant",
24 | "winrm_password": "vagrant",
25 | "winrm_timeout": "3h",
26 | "shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"",
27 | "post_shutdown_delay": "30s",
28 | "guest_additions_mode": "attach",
29 | "vboxmanage": [
30 | [
31 | "modifyvm",
32 | "{{.Name}}",
33 | "--memory",
34 | "4096"
35 | ],
36 | [
37 | "modifyvm",
38 | "{{.Name}}",
39 | "--cpus",
40 | "2"
41 | ],
42 | [
43 | "modifyvm",
44 | "{{.Name}}",
45 | "--vram",
46 | "32"
47 | ]
48 | ]
49 | }
50 | ],
51 | "provisioners": [
52 | {
53 | "type": "powershell",
54 | "scripts": ["provision.ps1"],
55 | "environment_vars": ["devtools={{user `devtools`}}"]
56 | },
57 | {
58 | "type": "windows-restart",
59 | "restart_timeout": "10m"
60 | }
61 | ],
62 | "post-processors": [
63 | {
64 | "type": "vagrant",
65 | "output": "{{.Provider}}_windows1803.box",
66 | "vagrantfile_template": "windows1803/vagrantfile.template"
67 | }
68 | ]
69 | }
70 |
--------------------------------------------------------------------------------
/windows1803/vagrantfile.template:
--------------------------------------------------------------------------------
1 | # -*- mode: ruby -*-
2 | # vi: set ft=ruby :
3 |
4 | Vagrant.require_version ">= 1.6.2"
5 |
6 | Vagrant.configure("2") do |config|
7 | config.vm.box = "windows1803"
8 | config.vm.communicator = "winrm"
9 | config.vm.provider "virtualbox" do |v, override|
10 | v.customize ["setextradata", "global", "GUI/SuppressMessages", "all" ]
11 | v.customize ["modifyvm", :id, "--clipboard", "bidirectional"]
12 | end
13 | end
14 |
--------------------------------------------------------------------------------
/windows2016/Autounattend.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | vagrant-win2016
6 | Microsoft
7 | Pacific Standard Time
8 |
9 |
10 | true
11 |
12 |
13 | true
14 |
15 |
16 | false
17 | false
18 |
19 |
20 |
21 |
22 | true
23 | Google
24 | Google
25 | http://www.google.com/search?q={searchTerms}
26 |
27 |
28 | true
29 | true
30 | about:blank
31 |
32 |
33 | false
34 |
35 |
36 | 0
37 |
38 |
39 |
40 |
41 | true
42 | Remote Desktop
43 | all
44 |
45 |
46 |
47 |
48 | true
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 | 0
57 | 1
58 |
59 |
60 |
61 | /IMAGE/NAME
62 | Windows Server 2016 SERVERSTANDARD
63 |
64 |
65 | OnError
66 | false
67 |
68 |
69 |
70 | true
71 | Vagrant Administrator
72 | Vagrant Inc.
73 |
74 |
75 |
76 |
77 |
78 | 1
79 | Primary
80 | true
81 |
82 |
83 |
84 |
85 | true
86 | false
87 | NTFS
88 |
89 | C
90 | 1
91 | 1
92 |
93 |
94 | 0
95 | true
96 |
97 | OnError
98 |
99 |
100 |
101 | en-US
102 | en-US
103 | en-US
104 | en-US
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 | dgBhAGcAcgBhAG4AdABQAGEAcwBzAHcAbwByAGQA
114 | false
115 |
116 | Vagrant User
117 | vagrant
118 | Administrators
119 | vagrant
120 |
121 |
122 |
123 |
124 |
125 | dgBhAGcAcgBhAG4AdABQAGEAcwBzAHcAbwByAGQA
126 | false
127 |
128 | true
129 | vagrant
130 |
131 |
132 | true
133 | true
134 | true
135 | true
136 | true
137 | Home
138 |
144 | 3
145 |
146 |
147 |
148 | powershell -NoLogo -ExecutionPolicy RemoteSigned -File a:\firstboot.ps1
149 | Start WinRM
150 | 1
151 |
152 |
153 |
154 |
155 |
156 |
157 | false
158 |
159 |
160 |
161 |
162 |
--------------------------------------------------------------------------------
/windows2016/packer.json:
--------------------------------------------------------------------------------
1 | {
2 | "variables": {
3 | "iso_url": "http://care.dlservice.microsoft.com/dl/download/1/4/9/149D5452-9B29-4274-B6B3-5361DBDA30BC/14393.0.161119-1705.RS1_REFRESH_SERVER_EVAL_X64FRE_EN-US.ISO",
4 | "iso_checksum": "1ce702a578a3cb1ac3d14873980838590f06d5b7101c5daaccbac9d73f1fb50f",
5 | "headless": "true",
6 | "devtools": "false"
7 | },
8 | "builders": [
9 | {
10 | "type": "virtualbox-iso",
11 | "communicator": "winrm",
12 | "disk_size": 61440,
13 | "floppy_files": [
14 | "windows2016/Autounattend.xml",
15 | "firstboot.ps1",
16 | "winrm.ps1"
17 | ],
18 | "guest_os_type": "Windows2016_64",
19 | "headless": "{{user `headless`}}",
20 | "iso_url": "{{user `iso_url`}}",
21 | "iso_checksum_type": "sha256",
22 | "iso_checksum": "{{user `iso_checksum`}}",
23 | "winrm_username": "vagrant",
24 | "winrm_password": "vagrant",
25 | "winrm_timeout": "3h",
26 | "shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"",
27 | "post_shutdown_delay": "30s",
28 | "guest_additions_mode": "attach",
29 | "vboxmanage": [
30 | [
31 | "modifyvm",
32 | "{{.Name}}",
33 | "--memory",
34 | "4096"
35 | ],
36 | [
37 | "modifyvm",
38 | "{{.Name}}",
39 | "--cpus",
40 | "2"
41 | ],
42 | [
43 | "modifyvm",
44 | "{{.Name}}",
45 | "--vram",
46 | "32"
47 | ]
48 | ]
49 | }
50 | ],
51 | "provisioners": [
52 | {
53 | "type": "powershell",
54 | "scripts": ["provision.ps1"],
55 | "environment_vars": ["devtools={{user `devtools`}}"]
56 | },
57 | {
58 | "type": "windows-restart",
59 | "restart_timeout": "10m"
60 | }
61 | ],
62 | "post-processors": [
63 | {
64 | "type": "vagrant",
65 | "output": "{{.Provider}}_windows2016.box",
66 | "vagrantfile_template": "windows2016/vagrantfile.template"
67 | }
68 | ]
69 | }
70 |
--------------------------------------------------------------------------------
/windows2016/vagrantfile.template:
--------------------------------------------------------------------------------
1 | # -*- mode: ruby -*-
2 | # vi: set ft=ruby :
3 |
4 | Vagrant.require_version ">= 1.6.2"
5 |
6 | Vagrant.configure("2") do |config|
7 | config.vm.box = "windows2016"
8 | config.vm.communicator = "winrm"
9 | config.vm.provider "virtualbox" do |v, override|
10 | v.customize ["setextradata", "global", "GUI/SuppressMessages", "all" ]
11 | v.customize ["modifyvm", :id, "--clipboard", "bidirectional"]
12 | end
13 | end
14 |
--------------------------------------------------------------------------------
/windows2019/Autounattend.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | vagrant-win2019
6 | Microsoft
7 | Pacific Standard Time
8 |
9 |
10 | true
11 |
12 |
13 | true
14 |
15 |
16 | false
17 | false
18 |
19 |
20 |
21 |
22 | true
23 | Google
24 | Google
25 | http://www.google.com/search?q={searchTerms}
26 |
27 |
28 | true
29 | true
30 | about:blank
31 |
32 |
33 | false
34 |
35 |
36 | 0
37 |
38 |
39 |
40 |
41 | true
42 | Remote Desktop
43 | all
44 |
45 |
46 |
47 |
48 | true
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 | 0
57 | 1
58 |
59 |
60 |
61 | /IMAGE/NAME
62 | Windows Server 2019 SERVERSTANDARD
63 |
64 |
65 | OnError
66 | false
67 |
68 |
69 |
70 | true
71 | Vagrant Administrator
72 | Vagrant Inc.
73 |
74 |
75 |
76 |
77 |
78 | 1
79 | Primary
80 | true
81 |
82 |
83 |
84 |
85 | true
86 | false
87 | NTFS
88 |
89 | C
90 | 1
91 | 1
92 |
93 |
94 | 0
95 | true
96 |
97 | OnError
98 |
99 |
100 |
101 | en-US
102 | en-US
103 | en-US
104 | en-US
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 | dgBhAGcAcgBhAG4AdABQAGEAcwBzAHcAbwByAGQA
114 | false
115 |
116 | Vagrant User
117 | vagrant
118 | Administrators
119 | vagrant
120 |
121 |
122 |
123 |
124 |
125 | dgBhAGcAcgBhAG4AdABQAGEAcwBzAHcAbwByAGQA
126 | false
127 |
128 | true
129 | vagrant
130 |
131 |
132 | true
133 | true
134 | true
135 | true
136 | true
137 | Home
138 |
144 | 3
145 |
146 |
147 |
148 | powershell -NoLogo -ExecutionPolicy RemoteSigned -File a:\firstboot.ps1
149 | Start WinRM
150 | 1
151 |
152 |
153 |
154 |
155 |
156 |
157 | false
158 |
159 |
160 |
161 |
162 |
--------------------------------------------------------------------------------
/windows2019/packer.json:
--------------------------------------------------------------------------------
1 | {
2 | "variables": {
3 | "iso_url": "https://software-download.microsoft.com/download/sg/17763.253.190108-0006.rs5_release_svc_refresh_SERVER_EVAL_x64FRE_en-us.iso",
4 | "iso_checksum": "57faf4a2ea4484cfdf5e964c539313c061c4d9cac474e723d60405f2ea02d570",
5 | "headless": "true",
6 | "devtools": "false"
7 | },
8 | "builders": [
9 | {
10 | "type": "virtualbox-iso",
11 | "communicator": "winrm",
12 | "disk_size": 61440,
13 | "floppy_files": [
14 | "windows2019/Autounattend.xml",
15 | "firstboot.ps1",
16 | "winrm.ps1"
17 | ],
18 | "guest_os_type": "Windows2016_64",
19 | "headless": "{{user `headless`}}",
20 | "iso_url": "{{user `iso_url`}}",
21 | "iso_checksum_type": "sha256",
22 | "iso_checksum": "{{user `iso_checksum`}}",
23 | "winrm_username": "vagrant",
24 | "winrm_password": "vagrant",
25 | "winrm_timeout": "3h",
26 | "shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"",
27 | "post_shutdown_delay": "30s",
28 | "guest_additions_mode": "attach",
29 | "vboxmanage": [
30 | [
31 | "modifyvm",
32 | "{{.Name}}",
33 | "--memory",
34 | "4096"
35 | ],
36 | [
37 | "modifyvm",
38 | "{{.Name}}",
39 | "--cpus",
40 | "2"
41 | ],
42 | [
43 | "modifyvm",
44 | "{{.Name}}",
45 | "--vram",
46 | "32"
47 | ]
48 | ]
49 | }
50 | ],
51 | "provisioners": [
52 | {
53 | "type": "powershell",
54 | "scripts": ["provision.ps1"],
55 | "environment_vars": ["devtools={{user `devtools`}}"]
56 | },
57 | {
58 | "type": "windows-restart",
59 | "restart_timeout": "10m"
60 | }
61 | ],
62 | "post-processors": [
63 | {
64 | "type": "vagrant",
65 | "output": "{{.Provider}}_windows2019.box",
66 | "vagrantfile_template": "windows2019/vagrantfile.template"
67 | }
68 | ]
69 | }
70 |
--------------------------------------------------------------------------------
/windows2019/vagrantfile.template:
--------------------------------------------------------------------------------
1 | # -*- mode: ruby -*-
2 | # vi: set ft=ruby :
3 |
4 | Vagrant.require_version ">= 1.6.2"
5 |
6 | Vagrant.configure("2") do |config|
7 | config.vm.box = "windows2019"
8 | config.vm.communicator = "winrm"
9 | config.vm.provider "virtualbox" do |v, override|
10 | v.customize ["setextradata", "global", "GUI/SuppressMessages", "all" ]
11 | v.customize ["modifyvm", :id, "--clipboard", "bidirectional"]
12 | end
13 | end
14 |
--------------------------------------------------------------------------------
/winrm.ps1:
--------------------------------------------------------------------------------
1 | # This script runs on boot until Windows Updates complete
2 | # then it enables WinRM
3 |
4 | function WinUpdatesComplete() {
5 | $f = "C:\Windows\Temp\win-updates.log"
6 | if (!(Test-Path $f -PathType Leaf)) {
7 | return $false
8 | }
9 | return (select-string -Path $f -Pattern "Done Installing Windows Updates") -ne $null
10 | }
11 |
12 | $RegistryKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
13 | $RegistryEntry = "CheckUpdatesComplete"
14 |
15 | # Configure this script to run again if a reboot happens
16 | Set-ItemProperty -Path $RegistryKey -Name $RegistryEntry -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -ExecutionPolicy Bypass -File a:\winrm.ps1"
17 |
18 | # Block until we find that Windows Updates have completed
19 | while (!(WinUpdatesComplete)) {
20 | Start-Sleep -s 30
21 | }
22 |
23 | # Done Installing Windows Updates, remove this script from running on boot
24 | $prop = (Get-ItemProperty $RegistryKey).$RegistryEntry
25 | if ($prop) {
26 | Remove-ItemProperty -Path $RegistryKey -Name $RegistryEntry -ErrorAction SilentlyContinue
27 | }
28 |
29 | # Enable WinRM insecurely for local Packer provisioners
30 | Install-Module WindowsBox.WinRM -Force
31 | Enable-InsecureWinRM
32 |
--------------------------------------------------------------------------------