VMware Cloud Community
NBS_VM
Contributor
Contributor

Strange error deploying using OScustomizationspec

I"m getting the following error while trying to deploy using OScustomizationSpec.   Can someone help me out?

New-VM : 11/11/2016 9:08:52 AM    New-VM        The operation for the entity "TestTemplate" failed with the following message: "A specified parameter was not correct.

spec.options.changeSID"    At H:\Powershell scripts\vmcreate.ps1:16 char:1

+ New-VM -Name nbstemp001 -Template $template -VMHost $vmHost -OSCustomizationSpec ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [New-VM], InvalidArgument

    + FullyQualifiedErrorId : Client20_TaskServiceImpl_CheckServerSideTaskUpdates_OperationFailed,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM

Script for the error above:

$template = "testtemplate"

$vmhost = "esxiserver"

$sid = $true

Connect-VIServer 192.168.1.1

# 1. Create a simple customizations spec

$custSpec = New-OSCustomizationSpec -Type nonPersistent -OSType Windows -OrgName SomeBusiness -FullName Dude -Domain domain.ad  –DomainUsername user –DomainPassword password

Set-OSCustomizationSpec -OSCustomizationSpec $custSpec -ChangeSID $sid

# 2. Modify the default network customization settings

$custSpec | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress 192.168.1.2 -SubnetMask 255.255.255.0 -Dns 192.168.1.4 -DefaultGateway 192.168.1.3

# 3. Deploy a VM from a template using the newly created customization:

New-VM -Name nbstemp001 -Template $template -VMHost $vmHost -OSCustomizationSpec $custSpec

0 Kudos
2 Replies
LucD
Leadership
Leadership

Which PowerCLI version are you using?
Which vSphere version?
Which OS is the template?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
irodebush01
Contributor
Contributor

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

0 Kudos