├── .gitignore ├── LICENSE ├── README.md ├── scripts ├── bios │ ├── core │ │ └── autounattend.xml │ └── gui │ │ └── autounattend.xml ├── cleanup.ps1 ├── setup.ps1 ├── uefi │ ├── OVMF_VARS.fd │ ├── core │ │ ├── autounattend.iso │ │ └── autounattend.xml │ └── gui │ │ ├── autounattend.iso │ │ └── autounattend.xml ├── virtualbox-guest-additions.ps1 ├── vmware-tools.ps1 └── win-update.ps1 ├── win2022-core.json ├── win2022-core_uefi.json ├── win2022-gui.json └── win2022-gui_uefi.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Cache objects 2 | packer_cache/ 3 | output-virtualbox-iso/ 4 | output-vmware-iso/ 5 | 6 | # For built boxes 7 | *.box 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 eaksel 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # packer-Win2022 2 | 3 | ## What is packer-Win2022 ? 4 | 5 | packer-Win2022 is a set of configuration files used to build automated Windows Server 2022 virtual machine images using [Packer](https://www.packer.io/). 6 | This Packer configuration file allows you to build images for VMware Workstation, Oracle VM VirtualBox and QEMU (KVM). 7 | 8 | ## Prerequisites 9 | 10 | - [Packer](https://www.packer.io/downloads.html) 11 | - 12 | - A Hypervisor 13 | - [VMware Workstation](https://www.vmware.com/products/workstation-pro.html) 14 | - [Oracle VM VirtualBox](https://www.virtualbox.org/) 15 | 16 | ## How to use Packer 17 | 18 | Commands to create an automated VM image: 19 | 20 | To create a Windows Server 2022 VM image using VMware Workstation use the following commands: 21 | 22 | ```sh 23 | cd c:\packer-Win2022 24 | packer build -only=vmware-iso win2022-gui.json #Windows Server 2022 w/ GUI 25 | packer build -only=vmware-iso win2022-core.json #Windows Server 2022 Core 26 | packer build -only=vmware-iso win2022-gui_uefi.json #Windows Server 2022 w/ GUI using UEFI 27 | packer build -only=vmware-iso win2022-core_uefi.json #Windows Server 2022 Core using UEFI 28 | ``` 29 | 30 | To create a Windows Server 2022 VM image using Oracle VM VirtualBox use the following commands: 31 | 32 | ```sh 33 | cd c:\packer-Win2022 34 | packer build -only=virtualbox-iso win2022-gui.json #Windows Server 2022 w/ GUI 35 | packer build -only=virtualbox-iso win2022-core.json #Windows Server 2022 Core 36 | packer build -only=virtualbox-iso win2022-gui_uefi.json #Windows Server 2022 w/ GUI using UEFI 37 | packer build -only=virtualbox-iso win2022-core_uefi.json #Windows Server 2022 Core using UEFI 38 | ``` 39 | 40 | To create a Windows Server 2022 VM image using QEMU (KVM) use the following commands: 41 | 42 | ```sh 43 | cd packer-Win2022 44 | wget https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.229-1/virtio-win-0.1.229.iso 45 | packer build -only=qemu win2022-gui.json #Windows Server 2022 w/ GUI 46 | packer build -only=qemu win2022-core.json #Windows Server 2022 Core 47 | packer build -only=qemu win2022-gui_uefi.json #Windows Server 2022 w/ GUI using UEFI 48 | packer build -only=qemu win2022-core_uefi.json #Windows Server 2022 Core using UEFI 49 | ``` 50 | 51 | *If you omit the keyword "-only=" images for both Workstation and Virtualbox will be created.* 52 | 53 | By default the .iso of Windows Server 2022 is pulled from 54 | 55 | You can change the URL to one closer to your build server. To do so change the **"iso_url"** parameter in the **"variables"** section of the win2022-*.json file. 56 | 57 | ```json 58 | { 59 | "variables": { 60 | "iso_url": "https://software-download.microsoft.com/download/sg/20348.169.210806-2348.fe_release_svc_refresh_SERVER_EVAL_x64FRE_en-us.iso" 61 | } 62 | } 63 | ``` 64 | 65 | ## Configuring Input/User Locale & Timezone 66 | 67 | To set the input/user locale and timezone according to your preferences edit the following files: 68 | 69 | - ".\packer-Win2022\scripts\\core\autounattend.xml" 70 | - ".\packer-Win2022\scripts\\gui\autounattend.xml" 71 | 72 | ```xml 73 | 74 | 75 | fr-FR 76 | fr-FR 77 | 78 | 79 | Romance Standard Time 80 | 81 | 82 | ``` 83 | 84 | ## Default credentials 85 | 86 | The default credentials for this VM image are: 87 | 88 | |Username|Password| 89 | |--------|--------| 90 | |administrator|packer| 91 | -------------------------------------------------------------------------------- /scripts/bios/core/autounattend.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | E:\amd64\2k22 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | en-US 16 | 17 | en-US 18 | en-US 19 | en-US 20 | en-US 21 | en-US 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 1 33 | Primary 34 | 499 35 | 36 | 37 | 38 | 2 39 | Primary 40 | true 41 | 42 | 43 | 44 | 45 | 1 46 | 1 47 | true 48 | 49 | NTFS 50 | 51 | 52 | 2 53 | 2 54 | 55 | NTFS 56 | C 57 | 58 | 59 | 0 60 | true 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | /IMAGE/INDEX 70 | 1 71 | 72 | 73 | 74 | 0 75 | 2 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | OnError 86 | 87 | true 88 | Packer 89 | Packer 90 | 91 | 92 | 93 | 94 | 95 | 96 | en-US 97 | en-US 98 | en-US 99 | en-US 100 | en-US 101 | 102 | 103 | 104 | packer-win2022 105 | Romance Standard Time 106 | 107 | 108 | 109 | true 110 | 111 | 112 | 113 | false 114 | true 115 | 116 | 117 | 118 | true 119 | 120 | 121 | 122 | true 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | packer 131 | true</PlainText> 132 | </Password> 133 | <Enabled>true</Enabled> 134 | <Username>Administrator</Username> 135 | </AutoLogon> 136 | <FirstLogonCommands> 137 | <SynchronousCommand wcm:action="add"> 138 | <CommandLine>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command if(Test-Path -Path "E:\virtio-win-guest-tools.exe") { E:\virtio-win-guest-tools.exe /install /quiet /norestart }</CommandLine> 139 | <Description>Install VirtIO drivers</Description> 140 | <Order>1</Order> 141 | <RequiresUserInput>true</RequiresUserInput> 142 | </SynchronousCommand> 143 | <SynchronousCommand wcm:action="add"> 144 | <CommandLine>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command New-SelfSignedCertificate -CertstoreLocation Cert:\LocalMachine\My -DnsName "WinRMCertificate"</CommandLine> 145 | <Description>Certificate for WinRM</Description> 146 | <Order>2</Order> 147 | <RequiresUserInput>true</RequiresUserInput> 148 | </SynchronousCommand> 149 | <SynchronousCommand wcm:action="add"> 150 | <CommandLine>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command Enable-PSRemoting -SkipNetworkProfileCheck -Force</CommandLine> 151 | <Description>Enable WinRM</Description> 152 | <Order>3</Order> 153 | <RequiresUserInput>true</RequiresUserInput> 154 | </SynchronousCommand> 155 | <SynchronousCommand wcm:action="add"> 156 | <CommandLine>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command ($cert = gci Cert:\LocalMachine\My\) -and (New-Item -Path WSMan:\LocalHost\Listener -Transport HTTPS -Address * -CertificateThumbPrint $cert.Thumbprint –Force)</CommandLine> 157 | <Description>Add HTTPS WinRM listener with previously generated certificate</Description> 158 | <Order>4</Order> 159 | <RequiresUserInput>true</RequiresUserInput> 160 | </SynchronousCommand> 161 | <SynchronousCommand wcm:action="add"> 162 | <CommandLine>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command New-NetFirewallRule -DisplayName 'Windows Remote Management (HTTPS-In)' -Name 'Windows Remote Management (HTTPS-In)' -Profile Any -LocalPort 5986 -Protocol TCP</CommandLine> 163 | <Description>Add firewall exception to TCP port 5986 for WinRM over HTTPS</Description> 164 | <Order>5</Order> 165 | <RequiresUserInput>true</RequiresUserInput> 166 | </SynchronousCommand> 167 | <SynchronousCommand wcm:action="add"> 168 | <CommandLine>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command Set-Item WSMan:\localhost\Service\Auth\Basic -Value $true</CommandLine> 169 | <Description>Enable Basic authentication</Description> 170 | <Order>6</Order> 171 | <RequiresUserInput>true</RequiresUserInput> 172 | </SynchronousCommand> 173 | <SynchronousCommand wcm:action="add"> 174 | <CommandLine>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command Stop-Service WinRM</CommandLine> 175 | <Description>Stop the WinRM service to allow the dism process to finish before packer executes scripts</Description> 176 | <Order>7</Order> 177 | <RequiresUserInput>true</RequiresUserInput> 178 | </SynchronousCommand> 179 | <SynchronousCommand wcm:action="add"> 180 | <CommandLine>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command dism /online /quiet /set-edition:ServerDatacenterCor /productkey:WX4NM-KYWYW-QJJR4-XV3QB-6VM33 /accepteula</CommandLine> 181 | <Order>8</Order> 182 | <Description>Switch from EVAL to VL</Description> 183 | </SynchronousCommand> 184 | <SynchronousCommand wcm:action="add"> 185 | <CommandLine>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command Restart-Computer -Force</CommandLine> 186 | <Order>9</Order> 187 | <Description>Restart computer to apply changes</Description> 188 | </SynchronousCommand> 189 | </FirstLogonCommands> 190 | <OOBE> 191 | <HideEULAPage>true</HideEULAPage> 192 | <HideLocalAccountScreen>true</HideLocalAccountScreen> 193 | <HideOEMRegistrationScreen>true</HideOEMRegistrationScreen> 194 | <HideOnlineAccountScreens>true</HideOnlineAccountScreens> 195 | <HideWirelessSetupInOOBE>true</HideWirelessSetupInOOBE> 196 | <NetworkLocation>Home</NetworkLocation> 197 | <ProtectYourPC>1</ProtectYourPC> 198 | </OOBE> 199 | <UserAccounts> 200 | <AdministratorPassword> 201 | <Value>packer</Value> 202 | <PlainText>true</PlainText> 203 | </AdministratorPassword> 204 | </UserAccounts> 205 | <RegisteredOwner/> 206 | </component> 207 | </settings> 208 | <settings pass="offlineServicing"> 209 | <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-LUA-Settings" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> 210 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-lua-settings --> 211 | <EnableLUA>false</EnableLUA> 212 | </component> 213 | </settings> 214 | <cpi:offlineImage xmlns:cpi="urn:schemas-microsoft-com:cpi" cpi:source=""/> 215 | </unattend> 216 | -------------------------------------------------------------------------------- /scripts/bios/gui/autounattend.xml: -------------------------------------------------------------------------------- 1 | <?xml version="1.0" encoding="utf-8"?> 2 | <unattend xmlns="urn:schemas-microsoft-com:unattend"> 3 | <settings pass="windowsPE"> 4 | <component name="Microsoft-Windows-PnpCustomizationsWinPE" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 5 | <DriverPaths> 6 | <PathAndCredentials wcm:keyValue="1" wcm:action="add"> 7 | <Path>E:\amd64\2k22</Path> 8 | <Credentials></Credentials> 9 | </PathAndCredentials> 10 | </DriverPaths> 11 | </component> 12 | <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-International-Core-WinPE" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> 13 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-international-core-winpe --> 14 | <SetupUILanguage> 15 | <UILanguage>en-US</UILanguage> 16 | </SetupUILanguage> 17 | <InputLocale>en-US</InputLocale> 18 | <SystemLocale>en-US</SystemLocale> 19 | <UILanguage>en-US</UILanguage> 20 | <UILanguageFallback>en-US</UILanguageFallback> 21 | <UserLocale>en-US</UserLocale> 22 | </component> 23 | <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> 24 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-setup --> 25 | <DiskConfiguration> 26 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-setup-diskconfiguration --> 27 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-setup-diskconfiguration-disk-modifypartitions-modifypartition-typeid --> 28 | <Disk wcm:action="add"> 29 | <CreatePartitions> 30 | <!-- Windows RE Tools partition --> 31 | <CreatePartition wcm:action="add"> 32 | <Order>1</Order> 33 | <Type>Primary</Type> 34 | <Size>499</Size> 35 | </CreatePartition> 36 | <!-- Windows partition --> 37 | <CreatePartition wcm:action="add"> 38 | <Order>2</Order> 39 | <Type>Primary</Type> 40 | <Extend>true</Extend> 41 | </CreatePartition> 42 | </CreatePartitions> 43 | <ModifyPartitions> 44 | <ModifyPartition wcm:action="add"> 45 | <Order>1</Order> 46 | <PartitionID>1</PartitionID> 47 | <Active>true</Active> 48 | <Label>boot</Label> 49 | <Format>NTFS</Format> 50 | </ModifyPartition> 51 | <ModifyPartition wcm:action="add"> 52 | <Order>2</Order> 53 | <PartitionID>2</PartitionID> 54 | <Label>Windows</Label> 55 | <Format>NTFS</Format> 56 | <Letter>C</Letter> 57 | </ModifyPartition> 58 | </ModifyPartitions> 59 | <DiskID>0</DiskID> 60 | <WillWipeDisk>true</WillWipeDisk> 61 | </Disk> 62 | </DiskConfiguration> 63 | <ImageInstall> 64 | <OSImage> 65 | <InstallFrom> 66 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-setup-imageinstall-dataimage-installfrom-metadata-key --> 67 | <!-- Get-WindowsImage -ImagePath D:\sources\install.wim --> 68 | <MetaData wcm:action="add"> 69 | <Key>/IMAGE/INDEX </Key> 70 | <Value>2</Value> 71 | </MetaData> 72 | </InstallFrom> 73 | <InstallTo> 74 | <DiskID>0</DiskID> 75 | <PartitionID>2</PartitionID> 76 | </InstallTo> 77 | </OSImage> 78 | </ImageInstall> 79 | <UserData> 80 | <!-- Product Key from http://technet.microsoft.com/en-us/library/jj612867.aspx --> 81 | <ProductKey> 82 | <!-- Do not uncomment the Key element if you are using trial ISOs --> 83 | <!-- You must uncomment the Key element (and optionally insert your own key) if you are using retail or volume license ISOs --> 84 | <!-- <Key>WX4NM-KYWYW-QJJR4-XV3QB-6VM33</Key> --> 85 | <WillShowUI>OnError</WillShowUI> 86 | </ProductKey> 87 | <AcceptEula>true</AcceptEula> 88 | <FullName>Packer</FullName> 89 | <Organization>Packer</Organization> 90 | </UserData> 91 | </component> 92 | </settings> 93 | <settings pass="specialize"> 94 | <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-International-Core" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> 95 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-international-core --> 96 | <InputLocale>en-US</InputLocale> 97 | <SystemLocale>en-US</SystemLocale> 98 | <UILanguage>en-US</UILanguage> 99 | <UILanguageFallback>en-US</UILanguageFallback> 100 | <UserLocale>en-US</UserLocale> 101 | </component> 102 | <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> 103 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-shell-setup --> 104 | <ComputerName>packer-win2022</ComputerName> 105 | <TimeZone>Romance Standard Time</TimeZone> 106 | </component> 107 | <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-ServerManager-SvrMgrNc" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> 108 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-servermanager-svrmgrnc --> 109 | <DoNotOpenServerManagerAtLogon>true</DoNotOpenServerManagerAtLogon> 110 | </component> 111 | <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-IE-ESC" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> 112 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-ie-esc --> 113 | <IEHardenAdmin>false</IEHardenAdmin> 114 | <IEHardenUser>true</IEHardenUser> 115 | </component> 116 | <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-OutOfBoxExperience" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> 117 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-outofboxexperience --> 118 | <DoNotOpenInitialConfigurationTasksAtLogon>true</DoNotOpenInitialConfigurationTasksAtLogon> 119 | </component> 120 | <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-Security-SPP-UX" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> 121 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-security-spp-ux --> 122 | <SkipAutoActivation>true</SkipAutoActivation> 123 | </component> 124 | </settings> 125 | <settings pass="oobeSystem"> 126 | <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> 127 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-shell-setup --> 128 | <AutoLogon> 129 | <Password> 130 | <Value>packer</Value> 131 | <PlainText>true</PlainText> 132 | </Password> 133 | <Enabled>true</Enabled> 134 | <Username>Administrator</Username> 135 | </AutoLogon> 136 | <FirstLogonCommands> 137 | <SynchronousCommand wcm:action="add"> 138 | <CommandLine>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command if(Test-Path -Path "E:\virtio-win-guest-tools.exe") { E:\virtio-win-guest-tools.exe /install /quiet /norestart }</CommandLine> 139 | <Description>Install VirtIO drivers</Description> 140 | <Order>1</Order> 141 | <RequiresUserInput>true</RequiresUserInput> 142 | </SynchronousCommand> 143 | <SynchronousCommand wcm:action="add"> 144 | <CommandLine>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command New-SelfSignedCertificate -CertstoreLocation Cert:\LocalMachine\My -DnsName "WinRMCertificate"</CommandLine> 145 | <Description>Certificate for WinRM</Description> 146 | <Order>2</Order> 147 | <RequiresUserInput>true</RequiresUserInput> 148 | </SynchronousCommand> 149 | <SynchronousCommand wcm:action="add"> 150 | <CommandLine>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command Enable-PSRemoting -SkipNetworkProfileCheck -Force</CommandLine> 151 | <Description>Enable WinRM</Description> 152 | <Order>3</Order> 153 | <RequiresUserInput>true</RequiresUserInput> 154 | </SynchronousCommand> 155 | <SynchronousCommand wcm:action="add"> 156 | <CommandLine>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command ($cert = gci Cert:\LocalMachine\My\) -and (New-Item -Path WSMan:\LocalHost\Listener -Transport HTTPS -Address * -CertificateThumbPrint $cert.Thumbprint –Force)</CommandLine> 157 | <Description>Add HTTPS WinRM listener with previously generated certificate</Description> 158 | <Order>4</Order> 159 | <RequiresUserInput>true</RequiresUserInput> 160 | </SynchronousCommand> 161 | <SynchronousCommand wcm:action="add"> 162 | <CommandLine>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command New-NetFirewallRule -DisplayName 'Windows Remote Management (HTTPS-In)' -Name 'Windows Remote Management (HTTPS-In)' -Profile Any -LocalPort 5986 -Protocol TCP</CommandLine> 163 | <Description>Add firewall exception to TCP port 5986 for WinRM over HTTPS</Description> 164 | <Order>5</Order> 165 | <RequiresUserInput>true</RequiresUserInput> 166 | </SynchronousCommand> 167 | <SynchronousCommand wcm:action="add"> 168 | <CommandLine>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command Set-Item WSMan:\localhost\Service\Auth\Basic -Value $true</CommandLine> 169 | <Description>Enable Basic authentication</Description> 170 | <Order>6</Order> 171 | <RequiresUserInput>true</RequiresUserInput> 172 | </SynchronousCommand> 173 | <SynchronousCommand wcm:action="add"> 174 | <CommandLine>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command Stop-Service WinRM</CommandLine> 175 | <Description>Stop the WinRM service to allow the dism process to finish before packer executes scripts</Description> 176 | <Order>7</Order> 177 | <RequiresUserInput>true</RequiresUserInput> 178 | </SynchronousCommand> 179 | <SynchronousCommand wcm:action="add"> 180 | <CommandLine>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command dism /online /quiet /set-edition:ServerDatacenter /productkey:WX4NM-KYWYW-QJJR4-XV3QB-6VM33 /accepteula</CommandLine> 181 | <Order>8</Order> 182 | <Description>Switch from EVAL to VL</Description> 183 | </SynchronousCommand> 184 | <SynchronousCommand wcm:action="add"> 185 | <CommandLine>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command Restart-Computer -Force</CommandLine> 186 | <Order>9</Order> 187 | <Description>Restart computer to apply changes</Description> 188 | </SynchronousCommand> 189 | </FirstLogonCommands> 190 | <OOBE> 191 | <HideEULAPage>true</HideEULAPage> 192 | <HideLocalAccountScreen>true</HideLocalAccountScreen> 193 | <HideOEMRegistrationScreen>true</HideOEMRegistrationScreen> 194 | <HideOnlineAccountScreens>true</HideOnlineAccountScreens> 195 | <HideWirelessSetupInOOBE>true</HideWirelessSetupInOOBE> 196 | <NetworkLocation>Home</NetworkLocation> 197 | <ProtectYourPC>1</ProtectYourPC> 198 | </OOBE> 199 | <UserAccounts> 200 | <AdministratorPassword> 201 | <Value>packer</Value> 202 | <PlainText>true</PlainText> 203 | </AdministratorPassword> 204 | </UserAccounts> 205 | <RegisteredOwner/> 206 | </component> 207 | </settings> 208 | <settings pass="offlineServicing"> 209 | <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-LUA-Settings" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> 210 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-lua-settings --> 211 | <EnableLUA>false</EnableLUA> 212 | </component> 213 | </settings> 214 | <cpi:offlineImage xmlns:cpi="urn:schemas-microsoft-com:cpi" cpi:source=""/> 215 | </unattend> -------------------------------------------------------------------------------- /scripts/cleanup.ps1: -------------------------------------------------------------------------------- 1 | Function Cleanup { 2 | 3 | Clear-Host 4 | 5 | ## Stops the windows update service. 6 | Get-Service -Name wuauserv | Stop-Service -Force -Verbose -ErrorAction SilentlyContinue 7 | 8 | ## Deletes the contents of windows software distribution. 9 | Get-ChildItem "C:\Windows\SoftwareDistribution\*" -Recurse -Force -Verbose -ErrorAction SilentlyContinue | Remove-Item -Force -Verbose -Recurse -ErrorAction SilentlyContinue 10 | 11 | ## Delets all files and folders in user's Temp folder. 12 | Get-ChildItem "C:\users\*\AppData\Local\Temp\*" -Recurse -Force -ErrorAction SilentlyContinue | Remove-Item -Force -Verbose -Recurse -ErrorAction SilentlyContinue 13 | 14 | ## Remove all files and folders in user's Temporary Internet Files. 15 | Get-ChildItem "C:\users\*\AppData\Local\Microsoft\Windows\Temporary Internet Files\*" -Recurse -Force -Verbose -ErrorAction SilentlyContinue | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue 16 | 17 | ## Deletes the contents of the Windows Temp folder. 18 | Get-ChildItem "C:\Windows\Temp\*" -Recurse -Force -Verbose -ErrorAction SilentlyContinue | Remove-Item -Force -Verbose -Recurse -ErrorAction SilentlyContinue 19 | } 20 | 21 | Cleanup -------------------------------------------------------------------------------- /scripts/setup.ps1: -------------------------------------------------------------------------------- 1 | # Remove Desktop from This PC 2 | Remove-Item "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{B4BFCC3A-DB2C-424C-B029-7FE99A87C641}" 3 | Remove-Item "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{B4BFCC3A-DB2C-424C-B029-7FE99A87C641}" 4 | # Remove Documents from This PC 5 | Remove-Item "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{A8CDFF1C-4878-43be-B5FD-F8091C1C60D0}" 6 | Remove-Item "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{d3162b92-9365-467a-956b-92703aca08af}" 7 | Remove-Item "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{A8CDFF1C-4878-43be-B5FD-F8091C1C60D0}" 8 | Remove-Item "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{d3162b92-9365-467a-956b-92703aca08af}" 9 | # Remove Downloads from This PC 10 | Remove-Item "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{374DE290-123F-4565-9164-39C4925E467B}" 11 | Remove-Item "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{088e3905-0323-4b02-9826-5d99428e115f}" 12 | Remove-Item "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{374DE290-123F-4565-9164-39C4925E467B}" 13 | Remove-Item "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{088e3905-0323-4b02-9826-5d99428e115f}" 14 | # Remove Music from This PC 15 | Remove-Item "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{1CF1260C-4DD0-4ebb-811F-33C572699FDE}" 16 | Remove-Item "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{3dfdf296-dbec-4fb4-81d1-6a3438bcf4de}" 17 | Remove-Item "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{1CF1260C-4DD0-4ebb-811F-33C572699FDE}" 18 | Remove-Item "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{3dfdf296-dbec-4fb4-81d1-6a3438bcf4de}" 19 | # Remove Pictures from This PC 20 | Remove-Item "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{3ADD1653-EB32-4cb0-BBD7-DFA0ABB5ACCA}" 21 | Remove-Item "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{24ad3ad4-a569-4530-98e1-ab02f9417aa8}" 22 | Remove-Item "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{3ADD1653-EB32-4cb0-BBD7-DFA0ABB5ACCA}" 23 | Remove-Item "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{24ad3ad4-a569-4530-98e1-ab02f9417aa8}" 24 | # Remove Videos from This PC 25 | Remove-Item "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{A0953C92-50DC-43bf-BE83-3742FED03C9C}" 26 | Remove-Item "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{f86fa3ab-70d2-4fc7-9c99-fcbf05467f3a}" 27 | Remove-Item "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{A0953C92-50DC-43bf-BE83-3742FED03C9C}" 28 | Remove-Item "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{f86fa3ab-70d2-4fc7-9c99-fcbf05467f3a}" 29 | # Remove 3D Objects from This PC 30 | Remove-Item "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{0DB7E03F-FC29-4DC6-9020-FF41B59E513A}" 31 | Remove-Item "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{0DB7E03F-FC29-4DC6-9020-FF41B59E513A}" 32 | 33 | # Disable Ease of Access keyboard shortcuts 34 | if ($(Get-WindowsEdition -Online).Edition -notmatch "cor") { 35 | Set-ItemProperty "HKCU:\Control Panel\Accessibility\StickyKeys" "Flags" "506" 36 | Set-ItemProperty "HKCU:\Control Panel\Accessibility\Keyboard Response" "Flags" "122" 37 | Set-ItemProperty "HKCU:\Control Panel\Accessibility\ToggleKeys" "Flags" "58" 38 | } 39 | 40 | if(!(Test-Path -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced")) { 41 | New-Item -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer" -Name "Advanced" 42 | } 43 | 44 | # Setting view options 45 | Set-ItemProperty "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced" "Hidden" 1 46 | Set-ItemProperty "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced" "HideFileExt" 0 47 | Set-ItemProperty "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced" "HideDrivesWithNoMedia" 0 48 | Set-ItemProperty "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced" "ShowSyncProviderNotifications" 0 49 | 50 | # Setting default explorer view to This PC 51 | Set-ItemProperty "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" "LaunchTo" 1 52 | 53 | # Show all icons in the taskbar notification area 54 | Set-ItemProperty "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer" -Name "EnableAutoTray" -Value 0 55 | 56 | # Small taskbar & combine when full 57 | Set-ItemProperty "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\" -Name "TaskbarSmallIcons" -Value 1 58 | Set-ItemProperty "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\" -Name "TaskbarGlomLevel" -Value 1 59 | 60 | # Disable hibernation 61 | Set-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Power\" -Name "HiberFileSizePercent" -Value 0 62 | Set-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Power\" -Name "HibernateEnabled" -Value 0 63 | 64 | # Disable sleep 65 | powercfg /change monitor-timeout-ac 0 66 | powercfg /change monitor-timeout-dc 0 67 | powercfg /change disk-timeout-ac 0 68 | powercfg /change disk-timeout-dc 0 69 | powercfg /change standby-timeout-ac 0 70 | powercfg /change standby-timeout-dc 0 71 | powercfg /change hibernate-timeout-ac 0 72 | powercfg /change hibernate-timeout-dc 0 73 | 74 | # Disable password expiration for Administrator 75 | Set-LocalUser Administrator -PasswordNeverExpires $true 76 | 77 | # Configure PowerShell prompt 78 | $psprofile = @' 79 | Set-Location / 80 | 81 | function prompt { 82 | Write-Host "[$(Get-Date -f 'HH:mm:ss')]" -ForegroundColor Yellow -NoNewline 83 | " PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) " 84 | } 85 | '@ 86 | 87 | New-Item $PROFILE -ItemType File -Force 88 | Set-Content -Path $PROFILE -Value $psprofile 89 | -------------------------------------------------------------------------------- /scripts/uefi/OVMF_VARS.fd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eaksel/packer-Win2022/3c2b86609035d59718126e0acbbd4f6dda638f44/scripts/uefi/OVMF_VARS.fd -------------------------------------------------------------------------------- /scripts/uefi/core/autounattend.iso: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eaksel/packer-Win2022/3c2b86609035d59718126e0acbbd4f6dda638f44/scripts/uefi/core/autounattend.iso -------------------------------------------------------------------------------- /scripts/uefi/core/autounattend.xml: -------------------------------------------------------------------------------- 1 | <?xml version="1.0" encoding="utf-8"?> 2 | <unattend xmlns="urn:schemas-microsoft-com:unattend"> 3 | <settings pass="windowsPE"> 4 | <component name="Microsoft-Windows-PnpCustomizationsWinPE" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 5 | <DriverPaths> 6 | <PathAndCredentials wcm:keyValue="1" wcm:action="add"> 7 | <Path>E:\amd64\2k22</Path> 8 | <Credentials></Credentials> 9 | </PathAndCredentials> 10 | </DriverPaths> 11 | </component> 12 | <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-International-Core-WinPE" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> 13 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-international-core-winpe --> 14 | <SetupUILanguage> 15 | <UILanguage>en-US</UILanguage> 16 | </SetupUILanguage> 17 | <InputLocale>en-US</InputLocale> 18 | <SystemLocale>en-US</SystemLocale> 19 | <UILanguage>en-US</UILanguage> 20 | <UILanguageFallback>en-US</UILanguageFallback> 21 | <UserLocale>en-US</UserLocale> 22 | </component> 23 | <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> 24 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-setup --> 25 | <DiskConfiguration> 26 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-setup-diskconfiguration --> 27 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-setup-diskconfiguration-disk-modifypartitions-modifypartition-typeid --> 28 | <Disk wcm:action="add"> 29 | <CreatePartitions> 30 | <!-- Windows RE Tools partition --> 31 | <CreatePartition wcm:action="add"> 32 | <Order>1</Order> 33 | <Type>Primary</Type> 34 | <Size>499</Size> 35 | </CreatePartition> 36 | <!-- System partition (ESP) --> 37 | <CreatePartition wcm:action="add"> 38 | <Order>2</Order> 39 | <Type>EFI</Type> 40 | <Size>100</Size> 41 | </CreatePartition> 42 | <!-- Microsoft reserved partition (MSR) --> 43 | <CreatePartition wcm:action="add"> 44 | <Order>3</Order> 45 | <Type>MSR</Type> 46 | <Size>128</Size> 47 | </CreatePartition> 48 | <!-- Windows partition --> 49 | <CreatePartition wcm:action="add"> 50 | <Order>4</Order> 51 | <Type>Primary</Type> 52 | <Extend>true</Extend> 53 | </CreatePartition> 54 | </CreatePartitions> 55 | <ModifyPartitions> 56 | <!-- Windows RE Tools partition --> 57 | <ModifyPartition wcm:action="add"> 58 | <Order>1</Order> 59 | <PartitionID>1</PartitionID> 60 | <Label>Recovery</Label> 61 | <Format>NTFS</Format> 62 | <TypeID>de94bba4-06d1-4d40-a16a-bfd50179d6ac</TypeID> 63 | </ModifyPartition> 64 | <!-- System partition (ESP) --> 65 | <ModifyPartition wcm:action="add"> 66 | <Order>2</Order> 67 | <PartitionID>2</PartitionID> 68 | <Label>System</Label> 69 | <Format>FAT32</Format> 70 | </ModifyPartition> 71 | <!-- MSR partition does not need to be modified --> 72 | <ModifyPartition wcm:action="add"> 73 | <Order>3</Order> 74 | <PartitionID>3</PartitionID> 75 | </ModifyPartition> 76 | <!-- Windows partition --> 77 | <ModifyPartition wcm:action="add"> 78 | <Order>4</Order> 79 | <PartitionID>4</PartitionID> 80 | <Label>Windows</Label> 81 | <Format>NTFS</Format> 82 | <Letter>C</Letter> 83 | </ModifyPartition> 84 | </ModifyPartitions> 85 | <DiskID>0</DiskID> 86 | <WillWipeDisk>true</WillWipeDisk> 87 | </Disk> 88 | </DiskConfiguration> 89 | <ImageInstall> 90 | <OSImage> 91 | <InstallFrom> 92 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-setup-imageinstall-dataimage-installfrom-metadata-key --> 93 | <!-- Get-WindowsImage -ImagePath D:\sources\install.wim --> 94 | <MetaData wcm:action="add"> 95 | <Key>/IMAGE/INDEX </Key> 96 | <Value>1</Value> 97 | </MetaData> 98 | </InstallFrom> 99 | <InstallTo> 100 | <DiskID>0</DiskID> 101 | <PartitionID>4</PartitionID> 102 | </InstallTo> 103 | </OSImage> 104 | </ImageInstall> 105 | <UserData> 106 | <!-- Product Key from http://technet.microsoft.com/en-us/library/jj612867.aspx --> 107 | <ProductKey> 108 | <!-- Do not uncomment the Key element if you are using trial ISOs --> 109 | <!-- You must uncomment the Key element (and optionally insert your own key) if you are using retail or volume license ISOs --> 110 | <!-- <Key>WX4NM-KYWYW-QJJR4-XV3QB-6VM33</Key> --> 111 | <WillShowUI>OnError</WillShowUI> 112 | </ProductKey> 113 | <AcceptEula>true</AcceptEula> 114 | <FullName>Packer</FullName> 115 | <Organization>Packer</Organization> 116 | </UserData> 117 | </component> 118 | </settings> 119 | <settings pass="specialize"> 120 | <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-International-Core" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> 121 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-international-core --> 122 | <InputLocale>en-US</InputLocale> 123 | <SystemLocale>en-US</SystemLocale> 124 | <UILanguage>en-US</UILanguage> 125 | <UILanguageFallback>en-US</UILanguageFallback> 126 | <UserLocale>en-US</UserLocale> 127 | </component> 128 | <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> 129 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-shell-setup --> 130 | <ComputerName>packer-win2022</ComputerName> 131 | <TimeZone>Romance Standard Time</TimeZone> 132 | </component> 133 | <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-ServerManager-SvrMgrNc" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> 134 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-servermanager-svrmgrnc --> 135 | <DoNotOpenServerManagerAtLogon>true</DoNotOpenServerManagerAtLogon> 136 | </component> 137 | <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-IE-ESC" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> 138 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-ie-esc --> 139 | <IEHardenAdmin>false</IEHardenAdmin> 140 | <IEHardenUser>true</IEHardenUser> 141 | </component> 142 | <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-OutOfBoxExperience" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> 143 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-outofboxexperience --> 144 | <DoNotOpenInitialConfigurationTasksAtLogon>true</DoNotOpenInitialConfigurationTasksAtLogon> 145 | </component> 146 | <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-Security-SPP-UX" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> 147 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-security-spp-ux --> 148 | <SkipAutoActivation>true</SkipAutoActivation> 149 | </component> 150 | </settings> 151 | <settings pass="oobeSystem"> 152 | <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> 153 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-shell-setup --> 154 | <AutoLogon> 155 | <Password> 156 | <Value>packer</Value> 157 | <PlainText>true</PlainText> 158 | </Password> 159 | <Enabled>true</Enabled> 160 | <Username>Administrator</Username> 161 | </AutoLogon> 162 | <FirstLogonCommands> 163 | <SynchronousCommand wcm:action="add"> 164 | <CommandLine>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command if(Test-Path -Path "E:\virtio-win-guest-tools.exe") { E:\virtio-win-guest-tools.exe /install /quiet /norestart }</CommandLine> 165 | <Description>Install VirtIO drivers</Description> 166 | <Order>1</Order> 167 | <RequiresUserInput>true</RequiresUserInput> 168 | </SynchronousCommand> 169 | <SynchronousCommand wcm:action="add"> 170 | <CommandLine>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command New-SelfSignedCertificate -CertstoreLocation Cert:\LocalMachine\My -DnsName "WinRMCertificate"</CommandLine> 171 | <Description>Certificate for WinRM</Description> 172 | <Order>2</Order> 173 | <RequiresUserInput>true</RequiresUserInput> 174 | </SynchronousCommand> 175 | <SynchronousCommand wcm:action="add"> 176 | <CommandLine>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command Enable-PSRemoting -SkipNetworkProfileCheck -Force</CommandLine> 177 | <Description>Enable WinRM</Description> 178 | <Order>3</Order> 179 | <RequiresUserInput>true</RequiresUserInput> 180 | </SynchronousCommand> 181 | <SynchronousCommand wcm:action="add"> 182 | <CommandLine>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command ($cert = gci Cert:\LocalMachine\My\) -and (New-Item -Path WSMan:\LocalHost\Listener -Transport HTTPS -Address * -CertificateThumbPrint $cert.Thumbprint –Force)</CommandLine> 183 | <Description>Add HTTPS WinRM listener with previously generated certificate</Description> 184 | <Order>4</Order> 185 | <RequiresUserInput>true</RequiresUserInput> 186 | </SynchronousCommand> 187 | <SynchronousCommand wcm:action="add"> 188 | <CommandLine>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command New-NetFirewallRule -DisplayName 'Windows Remote Management (HTTPS-In)' -Name 'Windows Remote Management (HTTPS-In)' -Profile Any -LocalPort 5986 -Protocol TCP</CommandLine> 189 | <Description>Add firewall exception to TCP port 5986 for WinRM over HTTPS</Description> 190 | <Order>5</Order> 191 | <RequiresUserInput>true</RequiresUserInput> 192 | </SynchronousCommand> 193 | <SynchronousCommand wcm:action="add"> 194 | <CommandLine>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command Set-Item WSMan:\localhost\Service\Auth\Basic -Value $true</CommandLine> 195 | <Description>Enable Basic authentication</Description> 196 | <Order>6</Order> 197 | <RequiresUserInput>true</RequiresUserInput> 198 | </SynchronousCommand> 199 | <SynchronousCommand wcm:action="add"> 200 | <CommandLine>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command Stop-Service WinRM</CommandLine> 201 | <Description>Stop the WinRM service to allow the dism process to finish before packer executes scripts</Description> 202 | <Order>7</Order> 203 | <RequiresUserInput>true</RequiresUserInput> 204 | </SynchronousCommand> 205 | <SynchronousCommand wcm:action="add"> 206 | <CommandLine>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command dism /online /quiet /set-edition:ServerDatacenterCor /productkey:WX4NM-KYWYW-QJJR4-XV3QB-6VM33 /accepteula</CommandLine> 207 | <Order>8</Order> 208 | <Description>Switch from EVAL to VL</Description> 209 | </SynchronousCommand> 210 | <SynchronousCommand wcm:action="add"> 211 | <CommandLine>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command Restart-Computer -Force</CommandLine> 212 | <Order>9</Order> 213 | <Description>Restart computer to apply changes</Description> 214 | </SynchronousCommand> 215 | </FirstLogonCommands> 216 | <OOBE> 217 | <HideEULAPage>true</HideEULAPage> 218 | <HideLocalAccountScreen>true</HideLocalAccountScreen> 219 | <HideOEMRegistrationScreen>true</HideOEMRegistrationScreen> 220 | <HideOnlineAccountScreens>true</HideOnlineAccountScreens> 221 | <HideWirelessSetupInOOBE>true</HideWirelessSetupInOOBE> 222 | <NetworkLocation>Home</NetworkLocation> 223 | <ProtectYourPC>1</ProtectYourPC> 224 | </OOBE> 225 | <UserAccounts> 226 | <AdministratorPassword> 227 | <Value>packer</Value> 228 | <PlainText>true</PlainText> 229 | </AdministratorPassword> 230 | </UserAccounts> 231 | <RegisteredOwner/> 232 | </component> 233 | </settings> 234 | <settings pass="offlineServicing"> 235 | <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-LUA-Settings" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> 236 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-lua-settings --> 237 | <EnableLUA>false</EnableLUA> 238 | </component> 239 | </settings> 240 | <cpi:offlineImage xmlns:cpi="urn:schemas-microsoft-com:cpi" cpi:source=""/> 241 | </unattend> -------------------------------------------------------------------------------- /scripts/uefi/gui/autounattend.iso: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eaksel/packer-Win2022/3c2b86609035d59718126e0acbbd4f6dda638f44/scripts/uefi/gui/autounattend.iso -------------------------------------------------------------------------------- /scripts/uefi/gui/autounattend.xml: -------------------------------------------------------------------------------- 1 | <?xml version="1.0" encoding="utf-8"?> 2 | <unattend xmlns="urn:schemas-microsoft-com:unattend"> 3 | <settings pass="windowsPE"> 4 | <component name="Microsoft-Windows-PnpCustomizationsWinPE" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 5 | <DriverPaths> 6 | <PathAndCredentials wcm:keyValue="1" wcm:action="add"> 7 | <Path>E:\amd64\2k22</Path> 8 | <Credentials></Credentials> 9 | </PathAndCredentials> 10 | </DriverPaths> 11 | </component> 12 | <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-International-Core-WinPE" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> 13 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-international-core-winpe --> 14 | <SetupUILanguage> 15 | <UILanguage>en-US</UILanguage> 16 | </SetupUILanguage> 17 | <InputLocale>en-US</InputLocale> 18 | <SystemLocale>en-US</SystemLocale> 19 | <UILanguage>en-US</UILanguage> 20 | <UILanguageFallback>en-US</UILanguageFallback> 21 | <UserLocale>en-US</UserLocale> 22 | </component> 23 | <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> 24 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-setup --> 25 | <DiskConfiguration> 26 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-setup-diskconfiguration --> 27 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-setup-diskconfiguration-disk-modifypartitions-modifypartition-typeid --> 28 | <Disk wcm:action="add"> 29 | <CreatePartitions> 30 | <!-- Windows RE Tools partition --> 31 | <CreatePartition wcm:action="add"> 32 | <Order>1</Order> 33 | <Type>Primary</Type> 34 | <Size>499</Size> 35 | </CreatePartition> 36 | <!-- System partition (ESP) --> 37 | <CreatePartition wcm:action="add"> 38 | <Order>2</Order> 39 | <Type>EFI</Type> 40 | <Size>100</Size> 41 | </CreatePartition> 42 | <!-- Microsoft reserved partition (MSR) --> 43 | <CreatePartition wcm:action="add"> 44 | <Order>3</Order> 45 | <Type>MSR</Type> 46 | <Size>128</Size> 47 | </CreatePartition> 48 | <!-- Windows partition --> 49 | <CreatePartition wcm:action="add"> 50 | <Order>4</Order> 51 | <Type>Primary</Type> 52 | <Extend>true</Extend> 53 | </CreatePartition> 54 | </CreatePartitions> 55 | <ModifyPartitions> 56 | <!-- Windows RE Tools partition --> 57 | <ModifyPartition wcm:action="add"> 58 | <Order>1</Order> 59 | <PartitionID>1</PartitionID> 60 | <Label>Recovery</Label> 61 | <Format>NTFS</Format> 62 | <TypeID>de94bba4-06d1-4d40-a16a-bfd50179d6ac</TypeID> 63 | </ModifyPartition> 64 | <!-- System partition (ESP) --> 65 | <ModifyPartition wcm:action="add"> 66 | <Order>2</Order> 67 | <PartitionID>2</PartitionID> 68 | <Label>System</Label> 69 | <Format>FAT32</Format> 70 | </ModifyPartition> 71 | <!-- MSR partition does not need to be modified --> 72 | <ModifyPartition wcm:action="add"> 73 | <Order>3</Order> 74 | <PartitionID>3</PartitionID> 75 | </ModifyPartition> 76 | <!-- Windows partition --> 77 | <ModifyPartition wcm:action="add"> 78 | <Order>4</Order> 79 | <PartitionID>4</PartitionID> 80 | <Label>Windows</Label> 81 | <Format>NTFS</Format> 82 | <Letter>C</Letter> 83 | </ModifyPartition> 84 | </ModifyPartitions> 85 | <DiskID>0</DiskID> 86 | <WillWipeDisk>true</WillWipeDisk> 87 | </Disk> 88 | </DiskConfiguration> 89 | <ImageInstall> 90 | <OSImage> 91 | <InstallFrom> 92 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-setup-imageinstall-dataimage-installfrom-metadata-key --> 93 | <!-- Get-WindowsImage -ImagePath D:\sources\install.wim --> 94 | <MetaData wcm:action="add"> 95 | <Key>/IMAGE/INDEX </Key> 96 | <Value>2</Value> 97 | </MetaData> 98 | </InstallFrom> 99 | <InstallTo> 100 | <DiskID>0</DiskID> 101 | <PartitionID>4</PartitionID> 102 | </InstallTo> 103 | </OSImage> 104 | </ImageInstall> 105 | <UserData> 106 | <!-- Product Key from http://technet.microsoft.com/en-us/library/jj612867.aspx --> 107 | <ProductKey> 108 | <!-- Do not uncomment the Key element if you are using trial ISOs --> 109 | <!-- You must uncomment the Key element (and optionally insert your own key) if you are using retail or volume license ISOs --> 110 | <!-- <Key>WX4NM-KYWYW-QJJR4-XV3QB-6VM33</Key> --> 111 | <WillShowUI>OnError</WillShowUI> 112 | </ProductKey> 113 | <AcceptEula>true</AcceptEula> 114 | <FullName>Packer</FullName> 115 | <Organization>Packer</Organization> 116 | </UserData> 117 | </component> 118 | </settings> 119 | <settings pass="specialize"> 120 | <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-International-Core" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> 121 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-international-core --> 122 | <InputLocale>en-US</InputLocale> 123 | <SystemLocale>en-US</SystemLocale> 124 | <UILanguage>en-US</UILanguage> 125 | <UILanguageFallback>en-US</UILanguageFallback> 126 | <UserLocale>en-US</UserLocale> 127 | </component> 128 | <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> 129 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-shell-setup --> 130 | <ComputerName>packer-win2022</ComputerName> 131 | <TimeZone>Romance Standard Time</TimeZone> 132 | </component> 133 | <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-ServerManager-SvrMgrNc" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> 134 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-servermanager-svrmgrnc --> 135 | <DoNotOpenServerManagerAtLogon>true</DoNotOpenServerManagerAtLogon> 136 | </component> 137 | <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-IE-ESC" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> 138 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-ie-esc --> 139 | <IEHardenAdmin>false</IEHardenAdmin> 140 | <IEHardenUser>true</IEHardenUser> 141 | </component> 142 | <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-OutOfBoxExperience" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> 143 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-outofboxexperience --> 144 | <DoNotOpenInitialConfigurationTasksAtLogon>true</DoNotOpenInitialConfigurationTasksAtLogon> 145 | </component> 146 | <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-Security-SPP-UX" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> 147 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-security-spp-ux --> 148 | <SkipAutoActivation>true</SkipAutoActivation> 149 | </component> 150 | </settings> 151 | <settings pass="oobeSystem"> 152 | <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> 153 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-shell-setup --> 154 | <AutoLogon> 155 | <Password> 156 | <Value>packer</Value> 157 | <PlainText>true</PlainText> 158 | </Password> 159 | <Enabled>true</Enabled> 160 | <Username>Administrator</Username> 161 | </AutoLogon> 162 | <FirstLogonCommands> 163 | <SynchronousCommand wcm:action="add"> 164 | <CommandLine>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command if(Test-Path -Path "E:\virtio-win-guest-tools.exe") { E:\virtio-win-guest-tools.exe /install /quiet /norestart }</CommandLine> 165 | <Description>Install VirtIO drivers</Description> 166 | <Order>1</Order> 167 | <RequiresUserInput>true</RequiresUserInput> 168 | </SynchronousCommand> 169 | <SynchronousCommand wcm:action="add"> 170 | <CommandLine>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command New-SelfSignedCertificate -CertstoreLocation Cert:\LocalMachine\My -DnsName "WinRMCertificate"</CommandLine> 171 | <Description>Certificate for WinRM</Description> 172 | <Order>2</Order> 173 | <RequiresUserInput>true</RequiresUserInput> 174 | </SynchronousCommand> 175 | <SynchronousCommand wcm:action="add"> 176 | <CommandLine>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command Enable-PSRemoting -SkipNetworkProfileCheck -Force</CommandLine> 177 | <Description>Enable WinRM</Description> 178 | <Order>3</Order> 179 | <RequiresUserInput>true</RequiresUserInput> 180 | </SynchronousCommand> 181 | <SynchronousCommand wcm:action="add"> 182 | <CommandLine>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command ($cert = gci Cert:\LocalMachine\My\) -and (New-Item -Path WSMan:\LocalHost\Listener -Transport HTTPS -Address * -CertificateThumbPrint $cert.Thumbprint –Force)</CommandLine> 183 | <Description>Add HTTPS WinRM listener with previously generated certificate</Description> 184 | <Order>4</Order> 185 | <RequiresUserInput>true</RequiresUserInput> 186 | </SynchronousCommand> 187 | <SynchronousCommand wcm:action="add"> 188 | <CommandLine>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command New-NetFirewallRule -DisplayName 'Windows Remote Management (HTTPS-In)' -Name 'Windows Remote Management (HTTPS-In)' -Profile Any -LocalPort 5986 -Protocol TCP</CommandLine> 189 | <Description>Add firewall exception to TCP port 5986 for WinRM over HTTPS</Description> 190 | <Order>5</Order> 191 | <RequiresUserInput>true</RequiresUserInput> 192 | </SynchronousCommand> 193 | <SynchronousCommand wcm:action="add"> 194 | <CommandLine>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command Set-Item WSMan:\localhost\Service\Auth\Basic -Value $true</CommandLine> 195 | <Description>Enable Basic authentication</Description> 196 | <Order>6</Order> 197 | <RequiresUserInput>true</RequiresUserInput> 198 | </SynchronousCommand> 199 | <SynchronousCommand wcm:action="add"> 200 | <CommandLine>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command Stop-Service WinRM</CommandLine> 201 | <Description>Stop the WinRM service to allow the dism process to finish before packer executes scripts</Description> 202 | <Order>7</Order> 203 | <RequiresUserInput>true</RequiresUserInput> 204 | </SynchronousCommand> 205 | <SynchronousCommand wcm:action="add"> 206 | <CommandLine>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command dism /online /quiet /set-edition:ServerDatacenter /productkey:WX4NM-KYWYW-QJJR4-XV3QB-6VM33 /accepteula</CommandLine> 207 | <Order>8</Order> 208 | <Description>Switch from EVAL to VL</Description> 209 | </SynchronousCommand> 210 | <SynchronousCommand wcm:action="add"> 211 | <CommandLine>%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Command Restart-Computer -Force</CommandLine> 212 | <Order>9</Order> 213 | <Description>Restart computer to apply changes</Description> 214 | </SynchronousCommand> 215 | </FirstLogonCommands> 216 | <OOBE> 217 | <HideEULAPage>true</HideEULAPage> 218 | <HideLocalAccountScreen>true</HideLocalAccountScreen> 219 | <HideOEMRegistrationScreen>true</HideOEMRegistrationScreen> 220 | <HideOnlineAccountScreens>true</HideOnlineAccountScreens> 221 | <HideWirelessSetupInOOBE>true</HideWirelessSetupInOOBE> 222 | <NetworkLocation>Home</NetworkLocation> 223 | <ProtectYourPC>1</ProtectYourPC> 224 | </OOBE> 225 | <UserAccounts> 226 | <AdministratorPassword> 227 | <Value>packer</Value> 228 | <PlainText>true</PlainText> 229 | </AdministratorPassword> 230 | </UserAccounts> 231 | <RegisteredOwner/> 232 | </component> 233 | </settings> 234 | <settings pass="offlineServicing"> 235 | <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-LUA-Settings" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> 236 | <!-- https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-lua-settings --> 237 | <EnableLUA>false</EnableLUA> 238 | </component> 239 | </settings> 240 | <cpi:offlineImage xmlns:cpi="urn:schemas-microsoft-com:cpi" cpi:source=""/> 241 | </unattend> -------------------------------------------------------------------------------- /scripts/virtualbox-guest-additions.ps1: -------------------------------------------------------------------------------- 1 | $ProgressPreference = "SilentlyContinue" 2 | 3 | $webclient = New-Object System.Net.WebClient 4 | $version_url = "http://download.virtualbox.org/virtualbox/LATEST.TXT" 5 | $version = $webclient.DownloadString($version_url) -replace '\s', '' 6 | $package = "VBoxGuestAdditions_$version.iso" 7 | $url = "http://download.virtualbox.org/virtualbox/$version/$package" 8 | 9 | Write-Output "***** Downloading Oracle VM VirtualBox Guest Additions" 10 | $iso = "$Env:TEMP\$package" 11 | $webclient.DownloadFile($url, $iso) 12 | 13 | Write-Output "***** Mounting disk image at $iso" 14 | Mount-DiskImage -ImagePath $iso 15 | 16 | Write-Output "***** Installing VirtualBox Certificates" 17 | $certdir = ((Get-DiskImage -ImagePath $iso | Get-Volume).Driveletter + ':\cert\') 18 | $VBoxCertUtil = ($certdir + 'VBoxCertUtil.exe') 19 | Get-ChildItem $certdir *.cer | ForEach-Object { & $VBoxCertUtil add-trusted-publisher $_.FullName --root $_.FullName } 20 | 21 | Write-Output "***** Installing VirtualBox Guest Additions" 22 | $exe = ((Get-DiskImage -ImagePath $iso | Get-Volume).Driveletter + ':\VBoxWindowsAdditions.exe') 23 | $parameters = '/S' 24 | 25 | Start-Process $exe $parameters -Wait 26 | 27 | Write-Output "***** Dismounting & Deleting $iso" 28 | Dismount-DiskImage -ImagePath $iso 29 | Remove-Item $iso -------------------------------------------------------------------------------- /scripts/vmware-tools.ps1: -------------------------------------------------------------------------------- 1 | $ProgressPreference = "SilentlyContinue" 2 | 3 | $webclient = New-Object System.Net.WebClient 4 | $version_url = "https://packages.vmware.com/tools/releases/latest/windows/x64/" 5 | $raw_package = $webclient.DownloadString($version_url) 6 | $raw_package -match "VMware-tools[\w-\d\.]*\.exe" 7 | $package = $Matches.0 8 | 9 | $url = "https://packages.vmware.com/tools/releases/latest/windows/x64/$package" 10 | $exe = "$Env:TEMP\$package" 11 | 12 | Write-Output "***** Downloading VMware Tools" 13 | $webclient.DownloadFile($url, $exe) 14 | 15 | $parameters = '/S /v "/qn REBOOT=R ADDLOCAL=ALL"' 16 | 17 | Write-Output "***** Installing VMware Tools" 18 | Start-Process $exe $parameters -Wait 19 | 20 | Write-Output "***** Deleting $exe" 21 | Remove-Item $exe -------------------------------------------------------------------------------- /scripts/win-update.ps1: -------------------------------------------------------------------------------- 1 | # Source : https://github.com/hashicorp/best-practices/blob/master/packer/scripts/windows/install_windows_updates.ps1 2 | # Silence progress bars in PowerShell, which can sometimes feed back strange 3 | # XML data to the Packer output. 4 | $ProgressPreference = "SilentlyContinue" 5 | 6 | Write-Output "***** Starting PSWindowsUpdate Installation" 7 | 8 | Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force 9 | Install-Module -Name PSWindowsUpdate -Force 10 | 11 | if (Get-ChildItem "C:\Program Files\WindowsPowerShell\Modules\PSWindowsUpdate") { 12 | Write-Output "***** PSWindowsUpdate installed successfully" 13 | } 14 | 15 | Write-Output "***** Starting Windows Update Installation" 16 | 17 | Try 18 | { 19 | Import-Module PSWindowsUpdate -ErrorAction Stop 20 | } 21 | Catch 22 | { 23 | Write-Error "***** Unable to Import PSWindowsUpdate" 24 | exit 1 25 | } 26 | 27 | if (Test-Path C:\Windows\Temp\PSWindowsUpdate.log) { 28 | Remove-Item -Path C:\Windows\Temp\PSWindowsUpdate.log 29 | } 30 | 31 | try { 32 | $updateCommand = {Import-Module PSWindowsUpdate; Get-WUInstall -AcceptAll -Install -IgnoreReboot | Out-File C:\Windows\Temp\PSWindowsUpdate.log} 33 | $TaskName = "PackerUpdate" 34 | 35 | $User = [Security.Principal.WindowsIdentity]::GetCurrent() 36 | $Scheduler = New-Object -ComObject Schedule.Service 37 | 38 | $Task = $Scheduler.NewTask(0) 39 | 40 | $RegistrationInfo = $Task.RegistrationInfo 41 | $RegistrationInfo.Description = $TaskName 42 | $RegistrationInfo.Author = $User.Name 43 | 44 | $Settings = $Task.Settings 45 | $Settings.Enabled = $True 46 | $Settings.StartWhenAvailable = $True 47 | $Settings.Hidden = $False 48 | 49 | $Action = $Task.Actions.Create(0) 50 | $Action.Path = "powershell" 51 | $Action.Arguments = "-Command $updateCommand" 52 | 53 | $Task.Principal.RunLevel = 1 54 | 55 | $Scheduler.Connect() 56 | $RootFolder = $Scheduler.GetFolder("\") 57 | $RootFolder.RegisterTaskDefinition($TaskName, $Task, 6, "SYSTEM", $Null, 1) | Out-Null 58 | $RootFolder.GetTask($TaskName).Run(0) | Out-Null 59 | 60 | Write-Output "***** The Windows Update log will be displayed below this message. No additional output indicates no updates were needed." 61 | do { 62 | sleep 1 63 | if ((Test-Path C:\Windows\Temp\PSWindowsUpdate.log) -and $script:reader -eq $null) { 64 | $script:stream = New-Object System.IO.FileStream -ArgumentList "C:\Windows\Temp\PSWindowsUpdate.log", "Open", "Read", "ReadWrite" 65 | $script:reader = New-Object System.IO.StreamReader $stream 66 | } 67 | if ($script:reader -ne $null) { 68 | $line = $Null 69 | do {$script:reader.ReadLine() 70 | $line = $script:reader.ReadLine() 71 | Write-Output $line 72 | } while ($line -ne $null) 73 | } 74 | } while ($Scheduler.GetRunningTasks(0) | Where-Object {$_.Name -eq $TaskName}) 75 | } finally { 76 | $RootFolder.DeleteTask($TaskName,0) 77 | [System.Runtime.Interopservices.Marshal]::ReleaseComObject($Scheduler) | Out-Null 78 | if ($script:reader -ne $null) { 79 | $script:reader.Close() 80 | $script:stream.Dispose() 81 | } 82 | } 83 | Write-Output "***** Ended Windows Update Installation" -------------------------------------------------------------------------------- /win2022-core.json: -------------------------------------------------------------------------------- 1 | { 2 | "variables": { 3 | "boot_wait": "5s", 4 | "disk_size": "40960", 5 | "iso_checksum": "4f1457c4fe14ce48c9b2324924f33ca4f0470475e6da851b39ccbf98f44e7852", 6 | "iso_url": "https://software-download.microsoft.com/download/sg/20348.169.210806-2348.fe_release_svc_refresh_SERVER_EVAL_x64FRE_en-us.iso", 7 | "memsize": "2048", 8 | "numvcpus": "2", 9 | "vm_name": "Win2022_20324-Core", 10 | "winrm_password" : "packer", 11 | "winrm_username" : "Administrator", 12 | "virtio_iso_path" : "virtio-win-0.1.229.iso" 13 | }, 14 | "builders": [ 15 | { 16 | "type": "vmware-iso", 17 | "guest_os_type": "windows2019srv-64", 18 | "vm_name":"{{user `vm_name`}}", 19 | "boot_wait": "{{user `boot_wait`}}", 20 | "disk_size": "{{user `disk_size`}}", 21 | "disk_type_id": "0", 22 | "headless": false, 23 | "iso_checksum": "{{user `iso_checksum`}}", 24 | "iso_url": "{{user `iso_url`}}", 25 | "communicator":"winrm", 26 | "winrm_username": "{{user `winrm_username`}}", 27 | "winrm_password": "{{user `winrm_password`}}", 28 | "winrm_use_ssl": true, 29 | "winrm_insecure": true, 30 | "winrm_timeout": "4h", 31 | "floppy_files": ["scripts/bios/core/autounattend.xml"], 32 | "shutdown_command": "shutdown /s /t 5 /f /d p:4:1 /c \"Packer Shutdown\"", 33 | "shutdown_timeout": "30m", 34 | "skip_compaction": false, 35 | "vmx_data": { 36 | "memsize": "{{user `memsize`}}", 37 | "numvcpus": "{{user `numvcpus`}}", 38 | "virtualHW.version": "14", 39 | "scsi0.virtualDev": "lsisas1068" 40 | } 41 | }, 42 | { 43 | "type": "virtualbox-iso", 44 | "guest_os_type": "Windows2019_64", 45 | "vm_name": "{{user `vm_name`}}", 46 | "iso_url": "{{user `iso_url`}}", 47 | "iso_checksum": "{{user `iso_checksum`}}", 48 | "guest_additions_mode": "disable", 49 | "headless": false, 50 | "boot_wait": "{{user `boot_wait`}}", 51 | "disk_size": "{{user `disk_size`}}", 52 | "communicator":"winrm", 53 | "winrm_username": "{{user `winrm_username`}}", 54 | "winrm_password": "{{user `winrm_password`}}", 55 | "winrm_use_ssl": true, 56 | "winrm_insecure": true, 57 | "winrm_timeout": "4h", 58 | "floppy_files": ["scripts/bios/core/autounattend.xml"], 59 | "shutdown_command": "shutdown /s /t 5 /f /d p:4:1 /c \"Packer Shutdown\"", 60 | "shutdown_timeout": "30m", 61 | "vboxmanage": [ 62 | ["modifyvm", "{{.Name}}", "--memory", "{{user `memsize`}}"], 63 | ["modifyvm", "{{.Name}}", "--cpus", "{{user `numvcpus`}}"] 64 | ] 65 | }, 66 | { 67 | "type": "qemu", 68 | "machine_type": "q35", 69 | "memory": "{{user `memsize`}}", 70 | "cpus": "{{user `numvcpus`}}", 71 | "vm_name": "{{user `vm_name`}}.qcow2", 72 | "iso_url": "{{user `iso_url`}}", 73 | "iso_checksum": "{{user `iso_checksum`}}", 74 | "headless": true, 75 | "boot_wait": "{{user `boot_wait`}}", 76 | "disk_size": "{{user `disk_size`}}", 77 | "disk_interface": "virtio-scsi", 78 | "disk_discard": "unmap", 79 | "disk_detect_zeroes": "unmap", 80 | "format": "qcow2", 81 | "communicator":"winrm", 82 | "winrm_username": "{{user `winrm_username`}}", 83 | "winrm_password": "{{user `winrm_password`}}", 84 | "winrm_use_ssl": true, 85 | "winrm_insecure": true, 86 | "winrm_timeout": "4h", 87 | "qemuargs": [ [ "-cdrom", "{{user `virtio_iso_path`}}" ] ], 88 | "floppy_files": ["scripts/bios/core/autounattend.xml"], 89 | "shutdown_command": "shutdown /s /t 5 /f /d p:4:1 /c \"Packer Shutdown\"", 90 | "shutdown_timeout": "30m" 91 | } 92 | ], 93 | "provisioners": [ 94 | { 95 | "type": "powershell", 96 | "only": ["vmware-iso"], 97 | "scripts": ["scripts/vmware-tools.ps1"], 98 | "pause_before": "1m" 99 | }, 100 | { 101 | "type": "powershell", 102 | "only": ["virtualbox-iso"], 103 | "scripts": ["scripts/virtualbox-guest-additions.ps1"], 104 | "pause_before": "1m" 105 | }, 106 | { 107 | "type": "powershell", 108 | "scripts": ["scripts/setup.ps1"] 109 | }, 110 | { 111 | "type": "windows-restart", 112 | "restart_timeout": "30m" 113 | }, 114 | { 115 | "type": "powershell", 116 | "scripts": ["scripts/win-update.ps1"] 117 | }, 118 | { 119 | "type": "windows-restart", 120 | "restart_timeout": "30m" 121 | }, 122 | { 123 | "type": "powershell", 124 | "scripts": ["scripts/win-update.ps1"] 125 | }, 126 | { 127 | "type": "windows-restart", 128 | "restart_timeout": "30m" 129 | }, 130 | { 131 | "type": "powershell", 132 | "scripts": ["scripts/cleanup.ps1"], 133 | "pause_before": "1m" 134 | } 135 | ] 136 | } 137 | -------------------------------------------------------------------------------- /win2022-core_uefi.json: -------------------------------------------------------------------------------- 1 | { 2 | "variables": { 3 | "boot_wait": "5s", 4 | "disk_size": "40960", 5 | "iso_checksum": "4f1457c4fe14ce48c9b2324924f33ca4f0470475e6da851b39ccbf98f44e7852", 6 | "iso_url": "https://software-download.microsoft.com/download/sg/20348.169.210806-2348.fe_release_svc_refresh_SERVER_EVAL_x64FRE_en-us.iso", 7 | "memsize": "2048", 8 | "numvcpus": "2", 9 | "vm_name": "Win2022_20324-Core", 10 | "winrm_password" : "packer", 11 | "winrm_username" : "Administrator", 12 | "virtio_iso_path" : "virtio-win-0.1.229.iso" 13 | }, 14 | "builders": [ 15 | { 16 | "type": "vmware-iso", 17 | "guest_os_type": "windows2019srv-64", 18 | "vm_name":"{{user `vm_name`}}", 19 | "boot_command": ["<spacebar>"], 20 | "boot_wait": "{{user `boot_wait`}}", 21 | "disk_size": "{{user `disk_size`}}", 22 | "disk_type_id": "0", 23 | "headless": false, 24 | "iso_checksum": "{{user `iso_checksum`}}", 25 | "iso_url": "{{user `iso_url`}}", 26 | "communicator":"winrm", 27 | "winrm_username": "{{user `winrm_username`}}", 28 | "winrm_password": "{{user `winrm_password`}}", 29 | "winrm_use_ssl": true, 30 | "winrm_insecure": true, 31 | "winrm_timeout": "4h", 32 | "floppy_files": ["scripts/uefi/core/autounattend.xml"], 33 | "shutdown_command": "shutdown /s /t 5 /f /d p:4:1 /c \"Packer Shutdown\"", 34 | "shutdown_timeout": "30m", 35 | "skip_compaction": false, 36 | "vmx_data": { 37 | "memsize": "{{user `memsize`}}", 38 | "numvcpus": "{{user `numvcpus`}}", 39 | "virtualHW.version": "14", 40 | "firmware": "efi", 41 | "scsi0.virtualDev": "lsisas1068" 42 | } 43 | }, 44 | { 45 | "type": "virtualbox-iso", 46 | "guest_os_type": "Windows2019_64", 47 | "vm_name": "{{user `vm_name`}}", 48 | "boot_command": ["<spacebar>"], 49 | "iso_url": "{{user `iso_url`}}", 50 | "iso_checksum": "{{user `iso_checksum`}}", 51 | "guest_additions_mode": "disable", 52 | "headless": false, 53 | "boot_wait": "{{user `boot_wait`}}", 54 | "disk_size": "{{user `disk_size`}}", 55 | "communicator":"winrm", 56 | "winrm_username": "{{user `winrm_username`}}", 57 | "winrm_password": "{{user `winrm_password`}}", 58 | "winrm_use_ssl": true, 59 | "winrm_insecure": true, 60 | "winrm_timeout": "4h", 61 | "shutdown_command": "shutdown /s /t 5 /f /d p:4:1 /c \"Packer Shutdown\"", 62 | "shutdown_timeout": "30m", 63 | "iso_interface": "sata", 64 | "vboxmanage": [ 65 | ["modifyvm", "{{.Name}}", "--memory", "{{user `memsize`}}"], 66 | ["modifyvm", "{{.Name}}", "--cpus", "{{user `numvcpus`}}"], 67 | ["modifyvm", "{{.Name}}", "--firmware", "EFI"], 68 | ["storageattach", "{{.Name}}", "--storagectl", "SATA Controller", "--type", "dvddrive", "--port", "3", "--medium", "./scripts/uefi/core/autounattend.iso"] 69 | ] 70 | }, 71 | { 72 | "type": "qemu", 73 | "machine_type": "q35", 74 | "efi_boot": true, 75 | "efi_firmware_vars": "scripts/uefi/OVMF_VARS.fd", 76 | "boot_command": [ 77 | "<wait10>", 78 | "reset<enter>", 79 | "<wait5>", 80 | "<spacebar>" 81 | ], 82 | "memory": "{{user `memsize`}}", 83 | "cpus": "{{user `numvcpus`}}", 84 | "vm_name": "{{user `vm_name`}}.qcow2", 85 | "iso_url": "{{user `iso_url`}}", 86 | "iso_checksum": "{{user `iso_checksum`}}", 87 | "headless": true, 88 | "boot_wait": "{{user `boot_wait`}}", 89 | "disk_size": "{{user `disk_size`}}", 90 | "disk_interface": "virtio-scsi", 91 | "disk_discard": "unmap", 92 | "disk_detect_zeroes": "unmap", 93 | "format": "qcow2", 94 | "communicator":"winrm", 95 | "winrm_username": "{{user `winrm_username`}}", 96 | "winrm_password": "{{user `winrm_password`}}", 97 | "winrm_use_ssl": true, 98 | "winrm_insecure": true, 99 | "winrm_timeout": "4h", 100 | "qemuargs": [ [ "-cdrom", "{{user `virtio_iso_path`}}" ] ], 101 | "floppy_files": ["scripts/uefi/core/autounattend.xml"], 102 | "shutdown_command": "shutdown /s /t 5 /f /d p:4:1 /c \"Packer Shutdown\"", 103 | "shutdown_timeout": "30m" 104 | } 105 | ], 106 | "provisioners": [ 107 | { 108 | "type": "powershell", 109 | "only": ["vmware-iso"], 110 | "scripts": ["scripts/vmware-tools.ps1"], 111 | "pause_before": "1m" 112 | }, 113 | { 114 | "type": "powershell", 115 | "only": ["virtualbox-iso"], 116 | "scripts": ["scripts/virtualbox-guest-additions.ps1"], 117 | "pause_before": "1m" 118 | }, 119 | { 120 | "type": "powershell", 121 | "scripts": ["scripts/setup.ps1"] 122 | }, 123 | { 124 | "type": "windows-restart", 125 | "restart_timeout": "30m" 126 | }, 127 | { 128 | "type": "powershell", 129 | "scripts": ["scripts/win-update.ps1"] 130 | }, 131 | { 132 | "type": "windows-restart", 133 | "restart_timeout": "30m" 134 | }, 135 | { 136 | "type": "powershell", 137 | "scripts": ["scripts/win-update.ps1"] 138 | }, 139 | { 140 | "type": "windows-restart", 141 | "restart_timeout": "30m" 142 | }, 143 | { 144 | "type": "powershell", 145 | "scripts": ["scripts/cleanup.ps1"], 146 | "pause_before": "1m" 147 | } 148 | ] 149 | } -------------------------------------------------------------------------------- /win2022-gui.json: -------------------------------------------------------------------------------- 1 | { 2 | "variables": { 3 | "boot_wait": "5s", 4 | "disk_size": "40960", 5 | "iso_checksum": "4f1457c4fe14ce48c9b2324924f33ca4f0470475e6da851b39ccbf98f44e7852", 6 | "iso_url": "https://software-download.microsoft.com/download/sg/20348.169.210806-2348.fe_release_svc_refresh_SERVER_EVAL_x64FRE_en-us.iso", 7 | "memsize": "2048", 8 | "numvcpus": "2", 9 | "vm_name": "Win2022_20324", 10 | "winrm_password" : "packer", 11 | "winrm_username" : "Administrator", 12 | "virtio_iso_path" : "virtio-win-0.1.229.iso" 13 | }, 14 | "builders": [ 15 | { 16 | "type": "vmware-iso", 17 | "guest_os_type": "windows2019srv-64", 18 | "vm_name":"{{user `vm_name`}}", 19 | "boot_wait": "{{user `boot_wait`}}", 20 | "disk_size": "{{user `disk_size`}}", 21 | "disk_type_id": "0", 22 | "headless": false, 23 | "iso_checksum": "{{user `iso_checksum`}}", 24 | "iso_url": "{{user `iso_url`}}", 25 | "communicator":"winrm", 26 | "winrm_username": "{{user `winrm_username`}}", 27 | "winrm_password": "{{user `winrm_password`}}", 28 | "winrm_use_ssl": true, 29 | "winrm_insecure": true, 30 | "winrm_timeout": "4h", 31 | "floppy_files": ["scripts/bios/gui/autounattend.xml"], 32 | "shutdown_command": "shutdown /s /t 5 /f /d p:4:1 /c \"Packer Shutdown\"", 33 | "shutdown_timeout": "30m", 34 | "skip_compaction": false, 35 | "vmx_data": { 36 | "memsize": "{{user `memsize`}}", 37 | "numvcpus": "{{user `numvcpus`}}", 38 | "virtualHW.version": "14", 39 | "scsi0.virtualDev": "lsisas1068" 40 | } 41 | }, 42 | { 43 | "type": "virtualbox-iso", 44 | "guest_os_type": "Windows2019_64", 45 | "vm_name": "{{user `vm_name`}}", 46 | "iso_url": "{{user `iso_url`}}", 47 | "iso_checksum": "{{user `iso_checksum`}}", 48 | "guest_additions_mode": "disable", 49 | "headless": false, 50 | "boot_wait": "{{user `boot_wait`}}", 51 | "disk_size": "{{user `disk_size`}}", 52 | "communicator":"winrm", 53 | "winrm_username": "{{user `winrm_username`}}", 54 | "winrm_password": "{{user `winrm_password`}}", 55 | "winrm_use_ssl": true, 56 | "winrm_insecure": true, 57 | "winrm_timeout": "4h", 58 | "floppy_files": ["scripts/bios/gui/autounattend.xml"], 59 | "shutdown_command": "shutdown /s /t 5 /f /d p:4:1 /c \"Packer Shutdown\"", 60 | "shutdown_timeout": "30m", 61 | "vboxmanage": [ 62 | ["modifyvm", "{{.Name}}", "--memory", "{{user `memsize`}}"], 63 | ["modifyvm", "{{.Name}}", "--cpus", "{{user `numvcpus`}}"] 64 | ] 65 | }, 66 | { 67 | "type": "qemu", 68 | "machine_type": "q35", 69 | "memory": "{{user `memsize`}}", 70 | "cpus": "{{user `numvcpus`}}", 71 | "vm_name": "{{user `vm_name`}}.qcow2", 72 | "iso_url": "{{user `iso_url`}}", 73 | "iso_checksum": "{{user `iso_checksum`}}", 74 | "headless": true, 75 | "boot_wait": "{{user `boot_wait`}}", 76 | "disk_size": "{{user `disk_size`}}", 77 | "disk_interface": "virtio-scsi", 78 | "disk_discard": "unmap", 79 | "disk_detect_zeroes": "unmap", 80 | "format": "qcow2", 81 | "communicator":"winrm", 82 | "winrm_username": "{{user `winrm_username`}}", 83 | "winrm_password": "{{user `winrm_password`}}", 84 | "winrm_use_ssl": true, 85 | "winrm_insecure": true, 86 | "winrm_timeout": "4h", 87 | "qemuargs": [ [ "-cdrom", "{{user `virtio_iso_path`}}" ] ], 88 | "floppy_files": ["scripts/bios/gui/autounattend.xml"], 89 | "shutdown_command": "shutdown /s /t 5 /f /d p:4:1 /c \"Packer Shutdown\"", 90 | "shutdown_timeout": "30m" 91 | } 92 | ], 93 | "provisioners": [ 94 | { 95 | "type": "powershell", 96 | "only": ["vmware-iso"], 97 | "scripts": ["scripts/vmware-tools.ps1"], 98 | "pause_before": "1m" 99 | }, 100 | { 101 | "type": "powershell", 102 | "only": ["virtualbox-iso"], 103 | "scripts": ["scripts/virtualbox-guest-additions.ps1"], 104 | "pause_before": "1m" 105 | }, 106 | { 107 | "type": "powershell", 108 | "scripts": ["scripts/setup.ps1"] 109 | }, 110 | { 111 | "type": "windows-restart", 112 | "restart_timeout": "30m" 113 | }, 114 | { 115 | "type": "powershell", 116 | "scripts": ["scripts/win-update.ps1"] 117 | }, 118 | { 119 | "type": "windows-restart", 120 | "restart_timeout": "30m" 121 | }, 122 | { 123 | "type": "powershell", 124 | "scripts": ["scripts/win-update.ps1"] 125 | }, 126 | { 127 | "type": "windows-restart", 128 | "restart_timeout": "30m" 129 | }, 130 | { 131 | "type": "powershell", 132 | "scripts": ["scripts/cleanup.ps1"], 133 | "pause_before": "1m" 134 | } 135 | ] 136 | } 137 | -------------------------------------------------------------------------------- /win2022-gui_uefi.json: -------------------------------------------------------------------------------- 1 | { 2 | "variables": { 3 | "boot_wait": "5s", 4 | "disk_size": "40960", 5 | "iso_checksum": "4f1457c4fe14ce48c9b2324924f33ca4f0470475e6da851b39ccbf98f44e7852", 6 | "iso_url": "https://software-download.microsoft.com/download/sg/20348.169.210806-2348.fe_release_svc_refresh_SERVER_EVAL_x64FRE_en-us.iso", 7 | "memsize": "2048", 8 | "numvcpus": "2", 9 | "vm_name": "Win2022_20324", 10 | "winrm_password" : "packer", 11 | "winrm_username" : "Administrator", 12 | "virtio_iso_path" : "virtio-win-0.1.229.iso" 13 | }, 14 | "builders": [ 15 | { 16 | "type": "vmware-iso", 17 | "guest_os_type": "windows2019srv-64", 18 | "vm_name":"{{user `vm_name`}}", 19 | "boot_command": ["<spacebar>"], 20 | "boot_wait": "{{user `boot_wait`}}", 21 | "disk_size": "{{user `disk_size`}}", 22 | "disk_type_id": "0", 23 | "headless": false, 24 | "iso_checksum": "{{user `iso_checksum`}}", 25 | "iso_url": "{{user `iso_url`}}", 26 | "communicator":"winrm", 27 | "winrm_username": "{{user `winrm_username`}}", 28 | "winrm_password": "{{user `winrm_password`}}", 29 | "winrm_use_ssl": true, 30 | "winrm_insecure": true, 31 | "winrm_timeout": "4h", 32 | "floppy_files": ["scripts/uefi/gui/autounattend.xml"], 33 | "shutdown_command": "shutdown /s /t 5 /f /d p:4:1 /c \"Packer Shutdown\"", 34 | "shutdown_timeout": "30m", 35 | "skip_compaction": false, 36 | "vmx_data": { 37 | "memsize": "{{user `memsize`}}", 38 | "numvcpus": "{{user `numvcpus`}}", 39 | "virtualHW.version": "14", 40 | "firmware": "efi", 41 | "scsi0.virtualDev": "lsisas1068" 42 | } 43 | }, 44 | { 45 | "type": "virtualbox-iso", 46 | "guest_os_type": "Windows2019_64", 47 | "vm_name": "{{user `vm_name`}}", 48 | "boot_command": ["<spacebar>"], 49 | "iso_url": "{{user `iso_url`}}", 50 | "iso_checksum": "{{user `iso_checksum`}}", 51 | "guest_additions_mode": "disable", 52 | "headless": false, 53 | "boot_wait": "{{user `boot_wait`}}", 54 | "disk_size": "{{user `disk_size`}}", 55 | "communicator":"winrm", 56 | "winrm_username": "{{user `winrm_username`}}", 57 | "winrm_password": "{{user `winrm_password`}}", 58 | "winrm_use_ssl": true, 59 | "winrm_insecure": true, 60 | "winrm_timeout": "4h", 61 | "shutdown_command": "shutdown /s /t 5 /f /d p:4:1 /c \"Packer Shutdown\"", 62 | "shutdown_timeout": "30m", 63 | "iso_interface": "sata", 64 | "vboxmanage": [ 65 | ["modifyvm", "{{.Name}}", "--memory", "{{user `memsize`}}"], 66 | ["modifyvm", "{{.Name}}", "--cpus", "{{user `numvcpus`}}"], 67 | ["modifyvm", "{{.Name}}", "--firmware", "EFI"], 68 | ["storageattach", "{{.Name}}", "--storagectl", "SATA Controller", "--type", "dvddrive", "--port", "3", "--medium", "./scripts/uefi/gui/autounattend.iso"] 69 | ] 70 | }, 71 | { 72 | "type": "qemu", 73 | "machine_type": "q35", 74 | "efi_boot": true, 75 | "efi_firmware_vars": "scripts/uefi/OVMF_VARS.fd", 76 | "boot_command": [ 77 | "<wait10>", 78 | "reset<enter>", 79 | "<wait5>", 80 | "<spacebar>" 81 | ], 82 | "memory": "{{user `memsize`}}", 83 | "cpus": "{{user `numvcpus`}}", 84 | "vm_name": "{{user `vm_name`}}.qcow2", 85 | "iso_url": "{{user `iso_url`}}", 86 | "iso_checksum": "{{user `iso_checksum`}}", 87 | "headless": true, 88 | "boot_wait": "{{user `boot_wait`}}", 89 | "disk_size": "{{user `disk_size`}}", 90 | "disk_interface": "virtio-scsi", 91 | "disk_discard": "unmap", 92 | "disk_detect_zeroes": "unmap", 93 | "format": "qcow2", 94 | "communicator":"winrm", 95 | "winrm_username": "{{user `winrm_username`}}", 96 | "winrm_password": "{{user `winrm_password`}}", 97 | "winrm_use_ssl": true, 98 | "winrm_insecure": true, 99 | "winrm_timeout": "4h", 100 | "qemuargs": [ [ "-cdrom", "{{user `virtio_iso_path`}}" ] ], 101 | "floppy_files": ["scripts/uefi/gui/autounattend.xml"], 102 | "shutdown_command": "shutdown /s /t 5 /f /d p:4:1 /c \"Packer Shutdown\"", 103 | "shutdown_timeout": "30m" 104 | } 105 | ], 106 | "provisioners": [ 107 | { 108 | "type": "powershell", 109 | "only": ["vmware-iso"], 110 | "scripts": ["scripts/vmware-tools.ps1"], 111 | "pause_before": "1m" 112 | }, 113 | { 114 | "type": "powershell", 115 | "only": ["virtualbox-iso"], 116 | "scripts": ["scripts/virtualbox-guest-additions.ps1"], 117 | "pause_before": "1m" 118 | }, 119 | { 120 | "type": "powershell", 121 | "scripts": ["scripts/setup.ps1"] 122 | }, 123 | { 124 | "type": "windows-restart", 125 | "restart_timeout": "30m" 126 | }, 127 | { 128 | "type": "powershell", 129 | "scripts": ["scripts/win-update.ps1"] 130 | }, 131 | { 132 | "type": "windows-restart", 133 | "restart_timeout": "30m" 134 | }, 135 | { 136 | "type": "powershell", 137 | "scripts": ["scripts/win-update.ps1"] 138 | }, 139 | { 140 | "type": "windows-restart", 141 | "restart_timeout": "30m" 142 | }, 143 | { 144 | "type": "powershell", 145 | "scripts": ["scripts/cleanup.ps1"], 146 | "pause_before": "1m" 147 | } 148 | ] 149 | } --------------------------------------------------------------------------------