windows-builder
hashicorp/agent-skills
Build Windows images with Packer using WinRM and PowerShell provisioners
What is windows-builder?
Automates Windows image creation for AWS, Azure, and VMware using Packer's WinRM communicator and PowerShell provisioners. Use this when you need to build Windows AMIs, managed images, or VM templates with consistent software and patches.
- Configure WinRM communication for Windows instances across cloud providers
- Install software and applications via Chocolatey or native Windows tools
- Apply Windows Updates and manage system reboots
- Set up IIS and other Windows features
- Clean up temporary files and caches before image finalization
- Handle PowerShell execution policies and long-running operations
How to install windows-builder
npx skills add https://github.com/hashicorp/agent-skills --skill windows-builder- Packer installed and configured
- Cloud provider credentials (AWS, Azure, or VMware)
- Understanding of HCL configuration syntax
- Network access to WinRM ports (5985/5986)
How to use windows-builder
- 1.Define a source block for your cloud provider (AWS, Azure, or VMware) with WinRM communicator settings
- 2.Create a user data script (setup-winrm.ps1) to configure WinRM on the base image
- 3.Add provisioners to install software, apply updates, and configure the system
- 4.Include a windows-restart provisioner after Windows Updates
- 5.Add cleanup provisioners to remove temporary files before image finalization
- 6.Run packer build and monitor for WinRM timeout or execution policy errors
Use cases
- Building Windows Server 2022 AMIs for AWS with pre-installed applications
- Creating Azure managed images with IIS and custom software
- Generating VMware templates with Windows Updates applied
- Automating Windows image builds with Chocolatey package management
- Creating golden images with consistent baseline configurations
- Infrastructure engineers building Windows infrastructure
- DevOps teams automating image creation pipelines
- Cloud architects standardizing Windows deployments
- System administrators creating reusable Windows templates
windows-builder FAQ
45-120 minutes per build, primarily due to Windows Updates which can take 1-2 hours. Use pre-patched base images when available to reduce build time.
Increase winrm_timeout to 15m or more, verify security groups allow ports 5985/5986, and check that the user data script completed successfully.
Add 'Set-ExecutionPolicy Bypass -Scope Process -Force' at the beginning of your PowerShell provisioners to bypass execution policy restrictions.
Use the windows-restart provisioner with a restart_timeout of at least 30m after running Windows Update provisioners.
Remove temporary files from C:\Windows\Temp, clear Windows Update cache, and stop unnecessary services to reduce image size.
Full instructions (SKILL.md)
Source of truth, from hashicorp/agent-skills.
name: windows-builder description: Build Windows images with Packer using WinRM communicator and PowerShell provisioners. Use when creating Windows AMIs, Azure images, or VMware templates.
Windows Builder
Platform-agnostic patterns for building Windows images with Packer.
Reference: Windows Builders
Note: Windows builds incur significant costs and time. Expect 45-120 minutes per build due to Windows Updates. Failed builds may leave resources running - always verify cleanup.
WinRM Communicator Setup
Windows requires WinRM for Packer communication.
AWS Example
source "amazon-ebs" "windows" {
region = "us-west-2"
instance_type = "t3.medium"
source_ami_filter {
filters = {
name = "Windows_Server-2022-English-Full-Base-*"
}
most_recent = true
owners = ["amazon"]
}
ami_name = "windows-server-2022-${local.timestamp}"
communicator = "winrm"
winrm_username = "Administrator"
winrm_use_ssl = true
winrm_insecure = true
winrm_timeout = "15m"
user_data_file = "scripts/setup-winrm.ps1"
}
WinRM Setup Script (scripts/setup-winrm.ps1)
<powershell>
# Configure WinRM
winrm quickconfig -q
winrm set winrm/config '@{MaxTimeoutms="1800000"}'
winrm set winrm/config/service '@{AllowUnencrypted="true"}'
winrm set winrm/config/service/auth '@{Basic="true"}'
# Configure firewall
netsh advfirewall firewall add rule name="WinRM 5985" protocol=TCP dir=in localport=5985 action=allow
netsh advfirewall firewall add rule name="WinRM 5986" protocol=TCP dir=in localport=5986 action=allow
# Restart WinRM
net stop winrm
net start winrm
</powershell>
Azure Example
source "azure-arm" "windows" {
client_id = var.client_id
client_secret = var.client_secret
subscription_id = var.subscription_id
tenant_id = var.tenant_id
managed_image_resource_group_name = "images-rg"
managed_image_name = "windows-${local.timestamp}"
os_type = "Windows"
image_publisher = "MicrosoftWindowsServer"
image_offer = "WindowsServer"
image_sku = "2022-datacenter-g2"
location = "East US"
vm_size = "Standard_D2s_v3"
# Azure auto-configures WinRM
communicator = "winrm"
winrm_use_ssl = true
winrm_insecure = true
winrm_timeout = "15m"
winrm_username = "packer"
}
PowerShell Provisioners
Install Software
build {
sources = ["source.amazon-ebs.windows"]
# Install Chocolatey
provisioner "powershell" {
inline = [
"Set-ExecutionPolicy Bypass -Scope Process -Force",
"iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))"
]
}
# Install applications
provisioner "powershell" {
inline = [
"choco install -y googlechrome",
"choco install -y 7zip",
]
}
# Install IIS
provisioner "powershell" {
inline = [
"Install-WindowsFeature -Name Web-Server -IncludeManagementTools"
]
}
}
Windows Updates
provisioner "powershell" {
inline = [
"Install-PackageProvider -Name NuGet -Force",
"Install-Module -Name PSWindowsUpdate -Force",
"Import-Module PSWindowsUpdate",
"Get-WindowsUpdate -Install -AcceptAll -AutoReboot",
]
timeout = "2h"
}
# Wait for reboots
provisioner "windows-restart" {
restart_timeout = "30m"
}
Cleanup
provisioner "powershell" {
inline = [
"# Clear temp files",
"Remove-Item -Path 'C:\\Windows\\Temp\\*' -Recurse -Force -ErrorAction SilentlyContinue",
"# Clear Windows Update cache",
"Stop-Service -Name wuauserv -Force",
"Remove-Item -Path 'C:\\Windows\\SoftwareDistribution\\*' -Recurse -Force -ErrorAction SilentlyContinue",
"Start-Service -Name wuauserv",
]
}
Common Issues
WinRM Timeout
- Increase
winrm_timeoutto 15m or more - Verify security group allows ports 5985/5986
- Check user data script completed successfully
PowerShell Execution Policy
provisioner "powershell" {
inline = [
"Set-ExecutionPolicy Bypass -Scope Process -Force",
"# Your commands here",
]
}
Long Build Times
- Windows Updates can take 1-2 hours
- Use pre-patched base images when available
- Set provisioner
timeout = "2h"
References
Related skills
More from hashicorp/agent-skills and the wider catalog.

aws-ami-builder
Build custom Amazon Machine Images (AMIs) with Packer's amazon-ebs builder for EC2 deployments.

azure-image-builder
Build custom Azure managed images and Compute Gallery images with Packer

azure-verified-modules
Azure Verified Modules (AVM) requirements and best practices for certified Terraform modules on Azure.

new-terraform-provider
Scaffold a new Terraform provider using the Plugin Framework.

gen-paylink-govilo
Upload files to Govilo and generate paid unlock links via Bot API.

ultracite
Zero-config linting and formatting for JavaScript/TypeScript projects with Biome, ESLint, or Oxlint.