This is turning out to be the hardest piece of the puzzle.
All I have been able to acomplish is renaming the VM (within the OS) I have not been able to figure out how to assign it a FIXED IP and assign the dns servers and GW.
most of the stuff I am finding online is not helping me.
$spec = New-OSCustomizationSpec -OSType linux -Domain 'mydomain'
Get-OSCustomizationSpec -Name $Spec | New-OSCustomizationSpec -Name teplatesc -Type Persistent
$osCust = Get-OSCustomizationSpec -Name teplatesc -Type Persistent
Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress 123.45.67.68 -SubnetMask 255.255.255.0 -DefaultGateway 123.45.67.99
New-VM -Name $displayname -OSCustomizationSpec $osCust -Template ( Get-template $tp ) -VMHost $HOST -Datastore $ds
If I can get this, im golden...
What I was trying to do is use that OSCustomizationSpec, take a non-persistent copy and change the IP settings on that non-persistent copy.
That way the original OSCustomizationSpec doesn't get changed.
The sequence is rather simple:
Get-OSCustomizationSpec -Name custemple | New-OSCustomizationSpec -Name temp -Type NonPersistent
Now we have a copy, which will live for the duration of your session, and on which we can do the NIC changes.
Again a rather simple sequence
Get-OSCustomizationSpec -Name temp | Get-OSCustomizationNicMapping |
Set-OSCustomizationNicMapping <all the new IP settings>
When that is done you can use the non-persistent one to configure you cloned VM
Get-VM -Name model | New-VM -OSCustomizationSpec temp ....
Did that resolve the confusion ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try something along these lines
New-OSCustomizationSpec -OSType linux -Domain 'mydomain' -Name teplatesc -Type Persistent
$osCust = Get-OSCustomizationSpec -Name teplatesc -Type Persistent |
Get-OSCustomizationNicMapping |
Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress 123.45.67.68 -SubnetMask 255.255.255.0 -DefaultGateway 123.45.67.99
New-VM -Name $displayname -OSCustomizationSpec $osCust -Template ( Get-template $tp ) -VMHost $HOST -Datastore $ds
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
Here is the error I receive.
What I want is to use the same OSCustomizationSpec for all build, but use a different OSCustomizationNicMapping..
Is that possible..?
-OSCustomizationSpec : 4/1/2013 1:50:59 PM New-OSCustomizationSpec An OSCustomizationSpec with the same name already exists on the server.
ew-OSCustomizationSpec <<<< -OSType linux -Domain 'mydomain' -Name teplatesc -Type Persistent
+ CategoryInfo : InvalidArgument: (:) [New-OSCustomizationSpec], ViError
+ FullyQualifiedErrorId : Client20_VmHostServiceImpl_NewCustomizationSpec_DuplicateCustomizationSpec,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewCustomizationSpec
-VM : Cannot bind parameter 'OSCustomizationSpec'. Cannot convert the "UseStaticIP:123.45.67.89" value of type "VMware.VimAutomation.ViCore.Impl.V1.OSCustomization.O
new-VM -Name $displayname -OSCustomizationSpec <<<< $osCust -Template ( Get-template $tp ) -VMHost $ESXHost -Datastore $ds
+ CategoryInfo : InvalidArgument: (:) [New-VM], ParameterBindingException
IF I use a different name other than ' -Name teplatesc and just errors out...
New-VM : Cannot convert 'System.Object[]' to the type 'VMware.VimAutomation.ViCore.Types.V1.OSCustomization.OSCustomizationSpec' req
uired by parameter 'OSCustomizationSpec'. Specified method is not supported.
At
+ New-VM -Name $displayname -OSCustomizationSpec <<<< $osCust -Template ( Get-template $template ) -VMHost $ESXHost -Datastore $ds
+ CategoryInfo : InvalidArgument: (:) [New-VM], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM
You can use a persistent oscustomizationspec and each time you run the script create a nonpersistent copy.
On that copy you then do the changes.
To enable running the script multiple times in 1 session, the script removes the nonpersisten spec each time.
Something like this for example
Get-OSCustomizationSpec -Name temp -Type NonPersistent |
Remove-OSCustomizationSpec -Confirm:$false
$oscust = New-OSCustomizationSpec -Name temp -Type NonPersistent -OSCustomizationSpec teplatesc |
Get-OSCustomizationNicMapping |
Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress 123.45.67.68 -SubnetMask 255.255.255.0 -DefaultGateway 123.45.67.99
New-VM -Name $displayname -OSCustomizationSpec $osCust -Template ( Get-template $tp ) -VMHost $HOST -Datastore $ds
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
How does it call the persistance spec to create the nonpersistant spec?
Get-OSCustomizationSpec : 4/2/2013 7:17:57 AM Get-OSCustomizationSpec Could not find Customization Specification with name 'temp'.
At
+ Get-OSCustomizationSpec <<<< -Name temp -Type NonPersistent |
+ CategoryInfo : ObjectNotFound: (temp:String) [Get-OSCustomizationSpec], VimException
+ FullyQualifiedErrorId : Common_CommonUtil_FilterCollection_ObjectNotFound,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetOSCustomizationSpec
New-OSCustomizationSpec : 4/2/2013 7:17:58 AM New-OSCustomizationSpec Could not find OSCustomizationSpec with name 'teplatesc'.
At
+ $osCust = New-OSCustomizationSpec <<<< -Name temp -Type NonPersistent -OSCustomizationSpec teplatesc |
+ CategoryInfo : ObjectNotFound: (teplatesc:String) [New-OSCustomizationSpec], VimException
+ FullyQualifiedErrorId : Core_ObnSelector_SelectObjectByNameCore_ObjectNotFound,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewCustomizationSpec
New-OSCustomizationSpec : 4/2/2013 7:17:58 AM New-OSCustomizationSpec Value cannot be found for the mandatory parameter OSCustomizationSpec
At
+ $osCust = New-OSCustomizationSpec <<<< -Name temp -Type NonPersistent -OSCustomizationSpec teplatesc |
+ CategoryInfo : NotSpecified: (:) [New-OSCustomizationSpec], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewCustomizationSpec
What OSCustomizationSpecs do you have in your session and saved.
Do a
Get-OSCustomizationSPec
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
custemple basic linux template Persistent Linux 2/15/2013 6:51:33 PM {vcenter server]
Sorry for my naive questions but this is where I get confused. But this spec has an IP tied to it. does it modify it since we plan to use the nonpersist,
This was created via vcenter
What I was trying to do is use that OSCustomizationSpec, take a non-persistent copy and change the IP settings on that non-persistent copy.
That way the original OSCustomizationSpec doesn't get changed.
The sequence is rather simple:
Get-OSCustomizationSpec -Name custemple | New-OSCustomizationSpec -Name temp -Type NonPersistent
Now we have a copy, which will live for the duration of your session, and on which we can do the NIC changes.
Again a rather simple sequence
Get-OSCustomizationSpec -Name temp | Get-OSCustomizationNicMapping |
Set-OSCustomizationNicMapping <all the new IP settings>
When that is done you can use the non-persistent one to configure you cloned VM
Get-VM -Name model | New-VM -OSCustomizationSpec temp ....
Did that resolve the confusion ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
sure did thanks!!!
Get-OSCustomizationSpec -Name custemple | New-OSCustomizationSpec -Name temp -Type NonPersistent -DnsServer $dns -DnsSuffix $dnsSuffix -Domain $domainname
So if I do this I receive the error, it appears it can not take the ppie, so how would it be possible to add :
$dns -DnsSuffix $dnsSuffix -Domain $domainname
New-OSCustomizationSpec : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or t
+ Get-OSCustomizationSpec -Name custemple | New-OSCustomizationSpec <<<< -Name temp -Type NonPersistent -DnsServer $dns -DnsSuffix $dnsSuffix -Domain $
+ CategoryInfo : InvalidArgument: (custemple:PSObject) [New-OSCustomizationSpec], ParameterBindingException
+ FullyQualifiedErrorId : InputObjectNotBound,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewCustomizationSpec
I'm afraid you are mixing 2 parametersets of the New-OSCustomizationSPec cmdlet.
1) The parameterset, called Cloning,that allows you to clone a OSCustomizationSpec
2) The parameterset, called Linux
or WindowsParameterset,
that allows you to create an OSCustomizationSpec from scratch.
What you can do is 1st create a temporary clone with the New-OSCustomizationSpec cmdlet, using the Cloning parameterset.
And then "get" the temporary oscustomizationspec and use Set-OSCustomizationSpec to make changes to it, like for example the DNS settings.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference