Hi Community
I'm used to deploy new VM from template with Customization Specification Manager file I made under vCenter 6.5U3 GUI.
For automation purposes, i'm trying to make PowerCLI (.ps1) scripts to ease VM deployment, right now i'm just at a test step (line by line execution) and just encounter a problem.
Template details :
- OS Type : Windows
- Take the VM name as Windows' computer name
- Time : GMT +01:00
- 1x NIC who prompt user for IP adress only (VLAN + netmask + gateway + DNS are already set in the template)
- add the vm into AD Domain
- Do not log in automatically as Administrator
- Sysprep + generate new SID
- Registration info : user : xxxx + Organization : xxxx
- Username and password already set too
My issue is that I'm able to deploy a new VM from template using PowerCli, but when I set -OSCustomizationSpec parameter to use my template, it didn't ask me the IP address, and it doesn't seems to use the VM name as Windows' computer name.
It doesn't seems that i can 100% use the template which was created on vCenter GUI..
Is there a problem from my CLI deployment or a known bug ? Do I have to recreate again the same template but for CLI ?
Thanks
Hi
this could help you:
PowerCLI – Deploy and customize a VM in vCenter – Metis IT
Alessandro Romeo
Hi,
I've just read the script and it seems to don't use any OSCustomization template, it make the deal but it's kind of wordy (write each time cpu, ram etc... whereas i already package it on a vcenter customization template)
I think there's something to do with OSCustomizationNicMapping function but i can't manage it ...
Hi,
How to Deploy Virtual Machines in vSphere Using PowerCLI
Virtual machine templates:
To create a template, create a new virtual machine, install the OS and configure any settings you would like to standardize with future virtual machines. Then you either clone or convert that virtual machine for a template.
Here is an example of cloning a new template called "Win7Template" from the VM "Win7VM".
C:> New-Template -VM 'Win2012VM' -Name "Server2012R2Template" -Datastore 'TestDatastore' -Location 'TestLocation'
OS Customization:
OS customization specifications are used to automate certain settings and tasks such as setting a computer's hostname and joining a computer to a domain. To create an OS specification we use the cmdlet New-OSCustomizationSpec in PowerCLI.
I created a new OS spec named "WindowsServer2012". I included the local administrator password, domain name, domain joining credentials, OS type, time zone and product key to be used. Note by default the network settings are configured for DHCP. You can set a static IP with the cmdlet New-OSCustomizationNicMapping.
C:> New-OSCustomizationSpec -Name 'WindowsServer2012' -FullName 'TestName' -OrgName 'TestOrg' -OSType Windows -ChangeSid -AdminPassword (Read-Host -AsSecureString) -Domain 'DOMAIN' -TimeZone 035 -DomainCredentials (Get-Credential) -ProductKey '1111-1111-1111-1111' -AutoLogonCount 1
Deploy a virtual machine from a template and customize settings:
Now that I have a VM template and OS customization specs, I can build a new virtual machine that will have the OS installed, be joined to a domain, set the product key and have the time zone set.
First, I place my OS Customization specs in the variable $OSSpecs.
$OSSpecs = Get-OSCustomizationSpec -Name 'WindowsServer2012'
Next, I place my VM template in a variable called $VMTemplate.
$VMTemplate = Get-Template -Name 'Server2012R2Template'
Finally, I deploy my VM with the New-VM cmdlet using my template and OS specs. I place the VM on the "VMHost-1" ESXi host and store the VM on the "TestDatastore" datastore.
New-VM -Name 'TestVM' -Template $VMTemplate -OSCustomizationSpec $OSSpec -VMHost 'VMHost-1' -Datastore 'TestDatastore
Set-OSCustomizationSpec - PowerCLI VMware.VimAutomation.Core Help Reference
Alessandro Romeo
Thanks for answering,
If i follow your example, the GUI specify to "prompt the user for ip address", i have the same behaviour in mine, but when you try to deploy a new vm with the same specification by using PowerCLI, it didn't prompt the ip address and i think we have to specify each parameters manually isn't it ?
So if i use "Set-OSCustomizationNicMapping" to my deploy command line, i'm afraid it will duplicate some settings I've already set using the GUI (dns server, ip to be prompted , netmask etc...)
Hi,
If you want to be sure, remove them from the customization and insert them into the PowerCli.
Or you can get the addresses by taking them from a CSV file, or set the ipmode = 'PromptUser' parameter.
Set-OSCustomizationNicMapping –IpMode UseStaticIP –IpAddress “192.168.0.101” –SubnetMask “255.255.252.0” –DefaultGateway “192.168.0.1” –Dns “192.168.0.10”
New-OSCustomizationNicMapping –OSCustomizationSpec “BasicWindowsSpec” –IpMode UseDhcp –Dns “192.168.0.10”, “192.168.0.20” –Wins “192.168.0.030”, “192.168.0.40”
Set-OSCustomizationNicMapping –IpMode promptUser –IpAddress “192.168.0.101” –SubnetMask “255.255.252.0” –DefaultGateway “192.168.0.1” –Dns “192.168.0.10”
VMware PowerCLI Forum - VMware {code}
http://kb.kaminskiengineering.com/node/353
Alessandro Romeo
I've tried the one with "UseStaticIP" parameter because it could help me in the future for using .csv doc.
But i still got an error with my cli (i didn't paste the $VMHost, $Template and $Spec but they're ok)
PS C:\> New-VM -Name 'WEB001' -VMHost $VMHost -Datastore 'DST_XXX' -Template $Template -OSCustomizationSpec $Spec | Set-OSCustomizationNicMapping -IPmode UseStaticIP -IpAddress "192.168.0.1" -SubnetMask "255.255.255.0" -DefaultGateway "192.168.0.1" -Dns "X.X.X.X.X","X.X.X.X.X"
New-VM : 31/07/2019 11:30:12 New-VM Server task failed: A specified parameter was not correct: nicsettings:adapter:ip
Au caractère Ligne:1 : 1
+ New-VM -Name 'WEB001' -VMHost $VMHost -Datastore 'DST_XXX ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-VM], VimException
+ FullyQualifiedErrorId : Security_Impl_TaskResultConverter_TaskNotSucceeded,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM
I tried with simple quote and double quote, nothing changes, i've also tried with only one DNS... but still the same error.
HI,
The network parameters must be entered without quotes and double quote.
The double DNS must be separated by a comma.
Try like this:
New-VM -Name 'WEB001' -VMHost $VMHost -Datastore 'DST_XXX' -Template $Template -OSCustomizationSpec $Spec | Set-OSCustomizationNicMapping -IPmode UseStaticIP -IpAddress 192.168.0.1 -SubnetMask 255.255.255.0 -DefaultGateway 192.168.0.1 -Dns X.X.X.X.X,X.X.X.X.X
-------------- Example 3 --------------
C:\PS>Get-OSCustomizationSpec mySpec | Get-OSCustomizationNicMapping | Set-OSCus
tomizationNicMapping -IpMode UseStaticIp -IpAddress 10.10.0.1 -SubnetMask 255.25
5.255.0 -DefaultGateway 10.10.0.1 -AlternateGateway 10.10.0.1 -Dns 10.10.150.1 -
PrimaryWins 10.10.150.2
Alessandro Romeo
Hi
Still the same error as i had about nicsettings adapter...
New-VM : 06/08/2019 10:44:29 New-VM Server task failed: A specified parameter was not correct: nicsettings:adapter:ip
Au caractère Ligne:1 : 1
+ New-VM -Name 'WEB001' -VMHost $VMHost -Datastore 'DST_SYS' ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-VM], VimException
+ FullyQualifiedErrorId : Security_Impl_TaskResultConverter_TaskNotSucceeded,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM
weird isn't it ? i only have 1 nic adapter on my template. Maybe i have to specify it ? I give a try with the "Position 1" parameter, i think it will works !
AlessandroRomeo68 any ideas ?
I've tried other settings but still the same error..
Hi,
How to automate VMWare VM creation using powercli oscustomizationspec -
Hi Alessandro,
Just did the tutorial on the link you posted, but still got an issue :
My win2016 template got only 1 nic, my OSCustomizationNicMapping one too, but when I want to deploy my VM it ends at 97% with this error
Any idea ?
Hi, the problem here is taht you have more than 1 NIC in your template and trying do customize just 1 NIC. Remove te additional NIC and try again.