Try the script below. The main thing I changed was moving the "ChangeSID" to the New-OSCustomizationSpec Params. You don't have to set the "Type" for the OSC as it defaults to "nonPersistent" and is saved in your current powershell session.
I added the hashtables as I believe it's easier to read and manage, just personal preference I guess.
$templateName = "testtemplate"
$vmhostName = "esxiserver"
$sid = $true
$IpMode = "UseStaticIP"
$IpAddress = "192.168.1.2"
$SubnetMask = "255.255.255.0"
$Dns = "192.168.1.4"
$DefaultGateway = "192.168.1.3"
Connect-VIServer 192.168.1.1
# 1. Create a simple customizations spec
$custSpecParms = @{
FullName = "Dude"
OSType = "Windows"
OrgName = "SomeBusiness"
Domain = "domain.ad"
DomainUsername = "user"
DomainPassword = "password"
ChangeSID = $sid
}
$custSpec = New-OSCustomizationSpec -OSCustomizationSpec @custSpecParms
# 2. Modify the default network customization settings
$custNicParms = @{
IpMode = $IpMode
IpAddress = $IpAddress
SubnetMask = $SubnetMask
Dns = $Dns
DefaultGateway = $DefaultGateway
}
$custSpec | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping @custNicParms
# 3. Deploy a VM from a template using the newly created customization:
$template = Get-Template -Name $templateName
$vmHost = Get-VMHost -Name $vmhostName
New-VM -Name nbstemp001 -Template $template -VMHost $vmHost -OSCustomizationSpec $custSpec