VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Error deploying using customization

Hi,

I am getting error while deploying VM through customization

Please help

Get-OSCustomizationSpec -Name "MyCust-2019" -ErrorAction SilentlyContinue |
Remove-OSCustomizationSpec -Confirm:$false
$sCust = @{
Name = "MyCust-2019"
OSType = 'Windows'
TimeZone = 033
ProductKey = 'xxxxx-xxxxx'
LicenseMode = 'Perserver'
LicenseMaxConnections = 5
GuiRunOnce = '"C:\Windows\System32\netdom.exe" join %COMPUTERNAME% /domain:mydc.com /ou:"OU=Servers,DC=mydc,DC=com" /userd:mydc.com\admin /passwordd:"P@ssw0rd@123" /reboot', 'net localgroup Administrators /ADD groupname "mydc\mydeploygrp"'
Type = 'Persistent'
FullName = 'mydc'
OrgName = 'mydc'
AdminPassword = 'password@123'
NamingScheme = 'VM'
AutoLogonCount = 1
Workgroup = 'WORKGROUP'
ChangeSID = $true
}
$Custo = New-OSCustomizationSpec $sCust
$sCustNic = @{
IpAddress = '192.168.11.100'
DefaultGateway = '192.168.11.1'
SubnetMask = '255.255.255.0'
Dns = '192.168.11.5'
}
Get-OSCustomizationNicMapping -OSCustomizationSpec $Custo | Set-OSCustomizationNicMapping $sCustNic

New-VM -Name $VM_Name -Template $Template -Datastore $Datastore -VMHost $VMHost | Set-VM -OSCustomizationSpec $Custo -Confirm:$false

$VM = Get-VM $VM_Name

$VM | Get-NetworkAdapter | Set-NetworkAdapter -PortGroup '192.168.11.x_1008' -Confirm:$false

Get-VM $vm | Start-VM -Confirm:$false

 

New-OSCustomizationSpec : A positional parameter cannot be found that accepts argument 'System.Collections.Hashtable'.
+ $Custo = New-OSCustomizationSpec $sCust
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-OSCustomizationSpec], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewCustomizationSpec

Get-OSCustomizationNicMapping : 11/14/2022 1:44:45 AM Get-OSCustomizationNicMapping Value cannot be found for the mandatory parameter OSCustomizatio
+ Get-OSCustomizationNicMapping -OSCustomizationSpec $Custo | Set-OSCus ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-OSCustomizationNicMapping], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetOSCustomizationNicMapping

 

Set-NetworkAdapter : 11/14/2022 1:45:00 AM Set-NetworkAdapter The specified parameter 'Portgroup' expects a single value, but your name criter
+ ... rkAdapter | Set-NetworkAdapter -PortGroup '172.27.3.x_3012' -Confirm: ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidResult: (System.Collecti...dObjectInterop]:List`1) [Set-NetworkAdapter], VimException
+ FullyQualifiedErrorId : Core_ObnSelector_SelectObjectByNameCore_MoreResultsThanExpected,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.SetNetw

Set-NetworkAdapter : 11/14/2022 1:45:00 AM Set-NetworkAdapter Value cannot be found for the mandatory parameter Portgroup
+ ... rkAdapter | Set-NetworkAdapter -PortGroup '172.27.3.x_3012' -Confirm: ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Set-NetworkAdapter], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.SetNetworkAdapter

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You can try explicitly specifying the ESXi node.

Get-VM $VM | 
Get-NetworkAdapter | 
Set-NetworkAdapter -PortGroup (Get-VirtualPortgroup -Name '192.168.11.x_1008' -VMHost $vm.VMHost) -Confirm:$false


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

View solution in original post

0 Kudos
13 Replies
LucD
Leadership
Leadership
Jump to solution

For splatting you have to use @ instead of $

$Custo = New-OSCustomizationSpec @sCust


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

After making the changes, I am getting below error

#Create the specifications and NIC Mappings for Win2016
Get-OSCustomizationSpec -Name "MyCust-2019" -ErrorAction SilentlyContinue |
Remove-OSCustomizationSpec -Confirm:$false
$sCust = @{
Name = "MyCust-2019"
OSType = 'Windows'
TimeZone = 033
ProductKey = 'xxxxx-xxxxx'
LicenseMode = 'Perserver'
LicenseMaxConnections = 5
GuiRunOnce = '"C:\Windows\System32\netdom.exe" join %COMPUTERNAME% /domain:mydc.com /ou:"OU=Servers,DC=mydc,DC=com" /userd:mydc.com\admin /passwordd:"P@ssw0rd@123" /reboot', 'net localgroup Administrators /ADD groupname "mydc\mydeploygrp"'
Type = 'Persistent'
FullName = 'mydc'
OrgName = 'mydc'
AdminPassword = 'password@123'
NamingScheme = 'VM'
AutoLogonCount = 1
Workgroup = 'WORKGROUP'
ChangeSID = $true
}
$Custo = New-OSCustomizationSpec @sCust
$sCustNic = @{
IpAddress = '192.168.11.100'
DefaultGateway = '192.168.11.1'
SubnetMask = '255.255.255.0'
Dns = '192.168.11.5'
}
$Custo1 = Get-OSCustomizationNicMapping -OSCustomizationSpec $Custo | Set-OSCustomizationNicMapping @sCustNic

New-VM -Name $VM_Name -Template $Template -Datastore $Datastore -VMHost $VMHost | Set-VM -OSCustomizationSpec $Custo1 -Confirm:$false

$VM = Get-VM $VM_Name

Get-VM $VM | Get-NetworkAdapter | Set-NetworkAdapter -PortGroup '192.168.11.x_1008' -Confirm:$false

Get-VM $vm | Start-VM -Confirm:$false

 

Set-OSCustomizationNicMapping : 11/14/2022 5:03:14 AM Set-OSCustomizationNicMapping If the IpMode parameter is set to "UseDhcp" you must not specify
+ ... -OSCustomizationSpec $Custo | Set-OSCustomizationNicMapping @sCustNic
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-OSCustomizationNicMapping], ViError
+ FullyQualifiedErrorId : Core_NicMappingCmdletBase_ValidateParameters_DhcpConflictingParameters,VMware.VimAutomation.ViCore.Cmdlets.Commands.SetOSCustomiza

 

Set-NetworkAdapter : 11/14/2022 5:03:31 AM Set-NetworkAdapter The specified parameter 'Portgroup' expects a single value, but your name criteria '192.168.11.x_1008' corresponds to multiple values.
+ ... NetworkAdapter | Set-NetworkAdapter -PortGroup $DV_PG -Confirm:$false
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidResult: (System.Collecti...dObjectInterop]:List`1) [Set-NetworkAdapter], VimException
+ FullyQualifiedErrorId : Core_ObnSelector_SelectObjectByNameCore_MoreResultsThanExpected,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.SetNetworkAdapter

Set-NetworkAdapter : 11/14/2022 5:03:31 AM Set-NetworkAdapter Value cannot be found for the mandatory parameter Portgroup
+ ... NetworkAdapter | Set-NetworkAdapter -PortGroup $DV_PG -Confirm:$false
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Set-NetworkAdapter], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.SetNetworkAdapter

Tags (1)
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You have to add -IpMode UseStaticIp on the Set-OSCustomizationNicMapping cmdlet.


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

I am getting the below error, after adding the usestaticip

Set-VM : Cannot bind parameter 'OSCustomizationSpec'. Cannot convert the "UseStaticIP:192.168.11.100" value of type "VMware.VimAutomation.ViCore.Impl.V1.OSCustomization.OSCustomizationNicMappingImpl" to type
"VMware.VimAutomation.ViCore.Types.V1.OSCustomization.OSCustomizationSpec".
+ ... tastore -VMHost $VMHost | Set-VM -OSCustomizationSpec $Custo1 -Confir ...
+ ~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-VM], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomation.ViCore.Cmdlets.Commands.SetVM

Get-VM : 11/14/2022 5:48:26 AM Get-VM VM with name 'TempTest1' was not found using the specified filter(s).
At D:\Jenkins\Scripts\deploytemplate\prod_jenkins_vmdeploy_1.0.ps1:72 char:7
+ $VM = Get-VM $VM_Name
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-VM], VimException
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

Get-VM : 11/14/2022 5:48:26 AM Get-VM VM with name 'TempTest1' was not found using the specified filter(s).
+ Get-VM $VM_Name | move-vm -InventoryLocation $Folder
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-VM], VimException
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

Get-VM : 11/14/2022 5:48:26 AM Get-VM VM with name 'TempTest1' was not found using the specified filter(s).
+ Get-VM $VM_Name | Get-NetworkAdapter | Set-NetworkAdapter -PortGroup ...
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-VM], VimException
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

Get-VM : 11/14/2022 5:48:27 AM Get-VM VM with name 'TempTest1' was not found using the specified filter(s).
+ Get-VM $VM_Name | Start-VM -Confirm:$false
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-VM], VimException
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Where and how did you add it?
Since you are using splatting, it has to be added in the hash table


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

Please find the script, which I tried

Get-OSCustomizationSpec -Name "MyCust-2019" -ErrorAction SilentlyContinue |
Remove-OSCustomizationSpec -Confirm:$false
$sCust = @{
Name = "MyCust-2019"
OSType = 'Windows'
TimeZone = 033
ProductKey = 'xxxxx-xxxxx'
LicenseMode = 'Perserver'
LicenseMaxConnections = 5
GuiRunOnce = '"C:\Windows\System32\netdom.exe" join %COMPUTERNAME% /domain:mydc.com /ou:"OU=Servers,DC=mydc,DC=com" /userd:mydc.com\admin /passwordd:"P@ssw0rd@123" /reboot', 'net localgroup Administrators /ADD groupname "mydc\mydeploygrp"'
Type = 'Persistent'
FullName = 'mydc'
OrgName = 'mydc'
AdminPassword = 'password@123'
NamingScheme = 'VM'
AutoLogonCount = 1
Workgroup = 'WORKGROUP'
ChangeSID = $true
}
$Custo = New-OSCustomizationSpec @sCust
$sCustNic = @{
IpMode = 'UseStaticIp'
IpAddress = '192.168.11.100'
DefaultGateway = '192.168.11.1'
SubnetMask = '255.255.255.0'
Dns = '192.168.11.5'
}
Get-OSCustomizationSpec $Custo | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping @sCustNic

New-VM -Name $VM_Name -Template $Template -Datastore $Datastore -VMHost $VMHost | Set-VM -OSCustomizationSpec $Custo -Confirm:$false

$VM = Get-VM $VM_Name

Get-VM $VM | Get-NetworkAdapter | Set-NetworkAdapter -PortGroup '192.168.11.x_1008' -Confirm:$false

Get-VM $vm | Start-VM -Confirm:$false

 

New-VM : 11/14/2022 7:04:34 AM New-VM Operation is not valid due to the current state of the object.
+ New-VM -Name $VM_Name -Template $Template -Datastore $Datastore -VMHo ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-VM], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM

Get-VM : 11/14/2022 7:04:34 AM Get-VM VM with name 'TempTest1' was not found using the specified filter(s).
+ $VM = Get-VM $VM_Name
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-VM], VimException
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

Get-VM : 11/14/2022 7:04:34 AM Get-VM VM with name 'TempTest1' was not found using the specified filter(s).
At D:\Jenkins\Scripts\deploytemplate\prod_jenkins_vmdeploy_1.0.ps1:81 char:1
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-VM], VimException
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

Get-VM : 11/14/2022 7:04:35 AM Get-VM VM with name 'TempTest1' was not found using the specified filter(s).
+ Get-VM $VM_Name | Get-NetworkAdapter | Set-NetworkAdapter -PortGroup ...
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-VM], VimException
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

Get-VM : 11/14/2022 7:04:35 AM Get-VM VM with name 'TempTest1' was not found using the specified filter(s).
+ Get-VM $VM_Name | Start-VM -Confirm:$false
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-VM], VimException
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That is yet another error, and definitely not the code that produced the previous errors.

Did you already stop/start your PowerCLI/PowerShell session?






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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

That did the trick, I closed the Powershell window and started a new session, that worked but I am getting error while setting the portgroup

we have portgroup on local switch on every esxi and it is named as 192.168.11.x_1008

 

Get-OSCustomizationSpec -Name "MyCust-2019" -ErrorAction SilentlyContinue |
Remove-OSCustomizationSpec -Confirm:$false
$sCust = @{
Name = "MyCust-2019"
OSType = 'Windows'
TimeZone = 033
ProductKey = 'xxxxx-xxxxx'
LicenseMode = 'Perserver'
LicenseMaxConnections = 5
GuiRunOnce = '"C:\Windows\System32\netdom.exe" join %COMPUTERNAME% /domain:mydc.com /ou:"OU=Servers,DC=mydc,DC=com" /userd:mydc.com\admin /passwordd:"P@ssw0rd@123" /reboot', 'net localgroup Administrators /ADD groupname "mydc\mydeploygrp"'
Type = 'Persistent'
FullName = 'mydc'
OrgName = 'mydc'
AdminPassword = 'password@123'
NamingScheme = 'VM'
AutoLogonCount = 1
Workgroup = 'WORKGROUP'
ChangeSID = $true
}
$Custo = New-OSCustomizationSpec @sCust
$sCustNic = @{
IpMode = 'UseStaticIp'
IpAddress = '192.168.11.100'
DefaultGateway = '192.168.11.1'
SubnetMask = '255.255.255.0'
Dns = '192.168.11.5'
}
Get-OSCustomizationSpec $Custo | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping @sCustNic

New-VM -Name $VM_Name -Template $Template -Datastore $Datastore -VMHost $VMHost | Set-VM -OSCustomizationSpec $Custo -Confirm:$false

$VM = Get-VM $VM_Name

Get-VM $VM | Get-NetworkAdapter | Set-NetworkAdapter -PortGroup '192.168.11.x_1008' -Confirm:$false

Get-VM $vm | Start-VM -Confirm:$false

 

Set-NetworkAdapter : 11/14/2022 7:31:57 AM Set-NetworkAdapter The specified parameter 'Portgroup' expects a single value, but your name criteria ''192.168.11.x_1008'' corresponds to multiple values.
+ ... NetworkAdapter | Set-NetworkAdapter -PortGroup $DV_PG -Confirm:$false
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidResult: (System.Collecti...dObjectInterop]:List`1) [Set-NetworkAdapter], VimException
+ FullyQualifiedErrorId : Core_ObnSelector_SelectObjectByNameCore_MoreResultsThanExpected,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.SetNetworkAdapter

Set-NetworkAdapter : 11/14/2022 7:31:57 AM Set-NetworkAdapter Value cannot be found for the mandatory parameter Portgroup
+ ... NetworkAdapter | Set-NetworkAdapter -PortGroup $DV_PG -Confirm:$false
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Set-NetworkAdapter], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.SetNetworkAdapter

0 Kudos
LucD
Leadership
Leadership
Jump to solution

It looks as if Get-VirtualPortgroup -Name ''192.168.11.x_1008'' returns more than 1 object.

Could it be that there are multiple vCenter or ESXi connections open?
Check $global:defaultviservers


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

Yes,  I am connecting to one vCenter and trying to deploy where we have same port group on all our esxi hosts.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can try explicitly specifying the ESXi node.

Get-VM $VM | 
Get-NetworkAdapter | 
Set-NetworkAdapter -PortGroup (Get-VirtualPortgroup -Name '192.168.11.x_1008' -VMHost $vm.VMHost) -Confirm:$false


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Thank you LucD, that worked perfectly 🙂
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Thank you LucD, that worked perfectly 🙂

0 Kudos