Howdy,
I feel this is a syntax problem. Need some review and help please.
Writing up a NEW-VM deploy script. The script is prompting the end user for all the custom details that is needed to create the VM. Then modifies a Cust Script in Custom Script Manager to deploy the VM from Template. Everything is going perfectly fine except assigning the Port Group.
According to this link : New-VM - vSphere PowerCLI Cmdlets Reference the Parameter is -NetworkName. In PowerGUI I am getting an error.
Here is the script:
# Connect to vCenter server
Connect-VIServer $vcserver
Get-OSCustomizationSpec TestScript1 | Get-OSCustomizationNicMapping | `
Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress $IP `
-SubnetMask $SM -DefaultGateway $GW -Dns 1.2.3.4,1.2.3.5
New-VM -Name $Name -Template TemplateNameHere -VMHost $VMHOST `
-Datastore $Datastore -networkname "VLAN ####" -OSCustomizationSpec TestScript1 `
-Confirm:$false -RunAsync
Setting -NetworkName with hard coded Port Group Name or with a variable gives the same result.
Here is the error I get in PowerGUI:
New-VM : Parameter set cannot be resolved using the specified named parameters.
At C:\Scripts\Massive Deploy Project\testdeploy1.ps1:23 char:5
+ New-VM -Name $Name -Template TemplateNameHere -VMHost $VMHOST `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-VM], ParameterBindingException
+ FullyQualifiedErrorId : AmbiguousParameterSet,VMware.VimAutomation.ViCore.Cmdlets.C
ommands.NewVM
Thanks
BostonTechGuy
You're mixing key parameters from different parametersets.
In this case you use the Template parameterset and in that case you can't use the NetworkName parameter.
Set the NetworkName later once the VM is created with the Set-NetworkAdapter cmdlet
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You're mixing key parameters from different parametersets.
In this case you use the Template parameterset and in that case you can't use the NetworkName parameter.
Set the NetworkName later once the VM is created with the Set-NetworkAdapter cmdlet
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Can you override the Port Group of the template during this process somehow? Like what I am doing with the Set-CustomizationNicMapping?
I'm afraid not.
The OSCustomization specs are intended to customize the guest OS, while you want to change the VM configuration.
But that shouldn't be a problem.
Something like this should work
$vm = New-VM ...
Get-NetworkAdapter -VM $vm | Set-NetworkAdapter -NetworkName netname
You might want to wait a bit after the New-VM till the guest OS is fully deployed.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks. I do have another script to change VLANs on a number of servers. Using the very same code you have listed above. I find it interesting that VMware doesnt have a way to deploy advanced options from a template via PowerCLI. You can do it in the vCenter Client, just before you commit to deploy you can click EDIT HARDWARE and make the changes. Interesting....
LucD. Thanks!
Thanks
BostonTechGuy
You made a correct observation on that, but on the other hand there is something to say about not providing all the possible options on 1 cmdlet.
Especially since there are alternatives to achieve the same result
I would hate to see cmdlets with a hundred parameters.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference