Before moving forward if you're unfamiliar with Packer I recommend reading for the basics. Furthermore there is a ton of great articles (I added a few below) on how to use Packer to build windows templates.
Packer Windows tutorials
My Packer Configuration
I use VMWare Workstation/Fusion
I use Packer version 1.2.3. I have tried newer versions of Packer and unfortunately I get inconsistent results when using the windows update functionality and therefore prevents me from building the template.
RTM ISO's but Trial Edition ISO's work as well.
Winrm for the Packer communication with the Administrator user and custom password.
Install latest version of VMWare tools.
Enable CredSSP.
Install PowerShell version 5.x
Perform sysprep and shutdown the box
vSphere post-processor to upload templates to vCenter.
More on the Administrator account requirement
I use the Administrator account simply because it's native to the OS and I want to keep my templates clean.
More on the CredSSP requirement.
Once you start building lab environments around Active Directory you will quickly notice that vagrant can only login with the local user which in my case is the Administrator account. What happens when you need to perform an action as another user such as the Domain Administrator ? This is where CredSSP comes in. When trying to automate installing Exchange, RDS, etc, you can use CredSSP with winrm to authenticate to the localhost as the Domain Administrator and perform the specific domain related actions. This will be further explained with examples in the Vagrant section.
More on the PowerShell version requirement
By installing the same version of PowerShell it is a guarantee that all PowerShell commands will work and therefore I don't need to create specific PowerShell scripts for different versions. Furthermore, this allows me to enable security controls such as PSLogging.
More on the sysprep requirement
Sysprep removes specific identifying elements such as the UUID from the initial template and forces the windows OS to generate a new one upon boot. This ultimately allows us to clone a Windows VM multiple times and each one will have a different UUID therefore making it unique. This is incredibly important as you build Active Directory environments because boxes with the same UUID can not join a domain.
Getting Started
I have created a github repo with sample configurations. You will need to make adjustments to fit your environment.
Sample Packer Configurations
Server 2019
The below is a sample Packer configuration for Windows Server 2019 which has PSv5.x installed by default.
The below is a sample Packer configuration for Windows Server 2012R2 which does not have PSv5.x installed and therefore requires first installing a newer version of .NET and then installing PSv5.x.