VMware Cloud Community
zewker
Contributor
Contributor
Jump to solution

New-VM oscustomizationspec problems

Hi,

I cannot seem to figure this out

First I make an new Non Persistent customizationspec

$osCust = Get-OSCustomizationSpec -Name tempcust | Get-OSCustomizationNicMapping |

Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress $ipaddr -SubnetMask $netmask -DefaultGateway $gateway -Dns $dns

Then i Create a new vm

$vm = New-VM -Name $name -VMHost $vmhost -Template $template -OSCustomizationSpec $osCust -Datastore $datastore -Location $folder -ErrorAction:Stop

I get the folling error on new-vm

I get the same error if i provide an IP-Address to -IpAddress instead of a variable

New-VM : Cannot bind parameter 'OSCustomizationSpec'. Cannot convert the "UseStaticIP:1.1.1.1" value of type "VMware.VimAutoma

tion.ViCore.Impl.V1.OSCustomization.OSCustomizationNicMappingImpl" to type "VMware.VimAutomation.ViCore.Types.V1.OSCustomization.OS

CustomizationSpec".

At line:4 char:22

+ -OSCustomizationSpec $osCust `

+                      ~~~~~~~

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

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

I've also tried not using -IpMode which should work if you use -IpAddress according to this:Set-OSCustomizationNicMapping however that doesn't seem to work either

IpAddress        Specify an IP address. Using this parameter automatically sets the IpMode parameter to UseStaticIp.

Any Ideas?

Regards

0 Kudos
1 Solution

Accepted Solutions
zewker
Contributor
Contributor
Jump to solution

So I've found the issue

Get-OSCustomizationSpec -name $custSpec | New-OSCustomizationSpec -Name tempcust 

$osCust = Get-OSCustomizationSpec -Name tempcust | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress $ipaddr -SubnetMask $netmask -DefaultGateway $gateway -Dns $dns

The second line was the problem, the type gets changed when it that way and therefore you cannot use that as the -OSCustomizationSpec variable

This works:


$custSpec | New-OSCustomizationSpec -Name tempcust

Get-OSCustomizationSpec -Name tempcust | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress $ipaddr -SubnetMask $netmask -DefaultGateway $gateway -Dns $dns

$osCust = Get-OSCustomizationSpec -Name tempcust






View solution in original post

0 Kudos
8 Replies
LucD
Leadership
Leadership
Jump to solution

Did you try with a persistent OSCustomizationSpec ?

Same issue ?


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

0 Kudos
zewker
Contributor
Contributor
Jump to solution

Yeah persistent works, but then i get DHCP and I'd like a static IP.

I could however use Set-VMGuestNetworkInterface when the machine is done but it would be nice to get the right IP right away

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That is a known issue I'm afraid with non-persistent OSCustomization specs.

Do you have a problem when you use the same Set-OSCustomizationNicMapping on a persistent OSCustomization spec ?


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

0 Kudos
zewker
Contributor
Contributor
Jump to solution

Ahh bummer 😕

Wouldn't that be a permanent change to the OSCustomization though?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

True, but I normally make a copy of my OSCustomizationSpec, which I throw away at the end of the script.


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

0 Kudos
zewker
Contributor
Contributor
Jump to solution

So I'll make a copy of my $custspec and create a new persistent and when the VM is done I delete it again?

I seem to get the same problem by using a persistent customization

Get-OSCustomizationSpec -name $custSpec | New-OSCustomizationSpec -Name tempcust

$osCust = Get-OSCustomizationSpec -Name tempcust | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress $ipaddr -SubnetMask $netmask -DefaultGateway $gateway -Dns $dns

$vm = New-VM -Name $name `

-VMHost $vmhost `

-Template $template `

-OSCustomizationSpec $osCust `

-Datastore $datastore `

-Location $folder `

-ErrorAction:Stop

New-VM : Cannot bind parameter 'OSCustomizationSpec'. Cannot convert the "UseStaticIP:1.1.1.1" value of type "VMware.VimAutoma

tion.ViCore.Impl.V1.OSCustomization.OSCustomizationNicMappingImpl" to type "VMware.VimAutomation.ViCore.Types.V1.OSCustomization.OS

CustomizationSpec".

At line:4 char:22

+ -OSCustomizationSpec $osCust `

+                      ~~~~~~~

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

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

Am I doing something wrong here?

$ipaddr.gettype()

IsPublic IsSerial Name                                     BaseType

-------- -------- ----                                     --------

True     True     String                                   System.Object

Get-OSCustomizationSpec $custSpec

Name                                         Description Type          OSType  LastUpdate           Server

----                                         ----------- ----          ------  ----------           ------

Admin                                     Persistent    Windows 2012-10-17 15:30:42  vcenter01

0 Kudos
cliffcahill
Enthusiast
Enthusiast
Jump to solution

I always found with the custom specs that i needed to have a second NIC card in my initial template that i was cloning from

This is what i have used successfully - Its pretty specific to my environment but i think you will get the idea.

param(  

$staging_vcenter = '192.168.101.101',

$OrgName = "test",

$VMPassword = "pass",

##### AMP Hosts #####

$Esxihost = 'esx01.build.local',

$VMVER = 'v9',

##### Management #####

$MGMT='MGMT_VLAN',

$MGMTVLAN='105',

$VMSubnet ="255.255.255.0",

$VMDefaultGateway ="192.168.105.1",

##### Customisation Specs #####

$OSCostumSpec_VC = "VC-Vcenter",

##### VM Templates #####

$vcenterTemplate = 'W2K12R2-STD-Template',

##### VM IP Addressing #####

$VCVMIP ="192.168.105.100",

##### VM Hostnames #####

$VCVM ="vc.domain.local",

##### VM License Keys #####

$WinProductKey_VC = "12345-12345-12345-12345-12345",

##### Domain, DNS, Timezone #####

$domainName = "build.local",

$DNS = "192.168.101.253",

$DNS2 = "192.168.101.252",

$TimeZone = "090"

)

#End Setting Paramters for Scripts

#Connect to vCenter

Write-Verbose "Connecting to vCenter"

$server = Connect-VIServer $vCenter -credential $(get-credential)

$myhost = Get-VMHost -Name $Esxihost

$h1ds1 = $myhost | Get-Datastore -name *local

New-OSCustomizationSpec -Name $OSCostumSpec_VC -OSType Windows -AdminPassword $VMPassword  -TimeZone $TimeZone -ProductKey $WinProductKey_VC -ChangeSid -OrgName $OrgName -NamingScheme Fixed -NamingPrefix $VCVM.split(".")[0] -fullname Administrator -Workgroup WORKGROUP

New-OSCustomizationNicMapping -OSCustomizationSpec $OSCostumSpec_VC -IpMode UseStaticIP -IPAddress $VCVMIP -SubnetMask $VMSubnet -DefaultGateway $VMGefaultGateway -Dns $DNS,$DNS2 -Position 1

New-VM -VMHost $Esxihost -Name $VCVM -Datastore $h1ds1 -Template $vcenterTemplate -OSCustomizationSpec $OSCostumSpec_VC

Get-VM -name $VCVM | Set-VM -Version $VMVER -confirm:$false

Get-NetworkAdapter -VM $VCVM | where {$_.Name -eq "Network adapter 2"} | Remove-NetworkAdapter -confirm:$false

Get-NetworkAdapter -VM $VCVM | where {$_.Name -eq "Network adapter 1"} | Set-NetworkAdapter -NetworkName $MGMT -confirm:$false -StartConnected:$true

Remove-OSCustomizationSpec $OSCostumSpec_VC -confirm:$false

Set-VM -VM $VCVM  -MemoryGB 24 -NumCpu 4  -Description "vCenter Server" -confirm:$false

$VMdisk = Get-HardDisk -vm $VCVM  -Name "Hard Disk 1"

Set-HardDisk -HardDisk $VMdisk -CapacityGB 60 -confirm:$false

$VMdisk2 = Get-HardDisk -vm $VCVM  -Name "Hard Disk 2"

Set-HardDisk -HardDisk $VMdisk2 -CapacityGB 40 -confirm:$false

0 Kudos
zewker
Contributor
Contributor
Jump to solution

So I've found the issue

Get-OSCustomizationSpec -name $custSpec | New-OSCustomizationSpec -Name tempcust 

$osCust = Get-OSCustomizationSpec -Name tempcust | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress $ipaddr -SubnetMask $netmask -DefaultGateway $gateway -Dns $dns

The second line was the problem, the type gets changed when it that way and therefore you cannot use that as the -OSCustomizationSpec variable

This works:


$custSpec | New-OSCustomizationSpec -Name tempcust

Get-OSCustomizationSpec -Name tempcust | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress $ipaddr -SubnetMask $netmask -DefaultGateway $gateway -Dns $dns

$osCust = Get-OSCustomizationSpec -Name tempcust






0 Kudos