See my answer to the other thread where you posted the same question.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
DNS is only required on Windows servers, this is not needed for Linux deployments as the DNS servers are defined within the template under /etc/resolv.conf.
Hi Nielse,
Thanks for your response..I have removed the DNS entry part from the PowerCLI Script and ran the script still its giving the below error .. the script should take IP Address DG details from the excel file but somehow its failing.. please chcek the same.
Below is my PCLI Script:
$vms = Import-CSV C:\Users\sg0217865\Desktop\NewVMs.csv
foreach ($vm in $vms){
$Template = Get-Template $vm.template
$VMHost = Get-VMHost $vm.host
$Datastore = Get-Datastore $vm.datastore
$OSCustomization = Get-OSCustomizationSpec LinuxTemplateforPCLI | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress $_.IP Address -SubnetMask $_.Subnet -DefaultGateway $_.Gateway
New-VM -Name $vm.name -OSCustomizationSpec $OSCustomization `
-Template $Template -VMHost $VMHost -Datastore $Datastore -RunAsync
}
Is that the correct screenshot? As it complains about DNS but I can't see it in your code.
Yes Nielse.. its the correct screenshot..I didnt understand why its giving DNS error eventhough the dns entry is removed from the Script.
Did you close the old connection to the vCenter and ran the script again? The customization should work without a problem
I closed the old connection and ran the script on new Window..still issue appears.
Can you give me a new script for deploying VMs from Template, and I want the script to take input from Excel file also the Customization for NIC shud be static.
Try something like this?
I had a hard time with this piece for setting up my provisioning script.. it took some time but I finally got it. I have been using it for a while now.
Mine also is for provisioning linux vm's.
hope it helps
David
Get-OSCustomizationSpec -Name temp | Remove-OSCustomizationSpec -Confirm:$false
Get-OSCustomizationSpec -Name custemple | New-OSCustomizationSpec -Name temp -Type NonPersistent
Get-OSCustomizationSpec -Name temp | Set-OSCustomizationSpec -Name temp -DnsServer $dns -DnsSuffix $dnsSuffix -Domain $domainname
Get-OSCustomizationSpec -Name temp | Get-OSCustomizationNicMapping |Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress $ip -SubnetMask $subnet -DefaultGateway $gw
Can you try the following (not tested, based on old script i have)
$vms = Import-CSV C:\Users\sg0217865\Desktop\NewVMs.csv
foreach ($vm in $vms){
$Template = Get-Template $vm.template
$VMHost = Get-VMHost $vm.host
$Datastore = Get-Datastore $vm.datastore
Get-OSCustomizationSpec LinuxTemplateforPCLI | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIp -IpAddress $_.IP Address -SubnetMask $_.Subnet -DefaultGateway $_.Gateway | Out-Null
New-VM -Name $vm.name -Template $Template -Datastore $Datastore -VMHost $VMHost -DiskStorageFormat Thin | Set-VM -OSCustomizationSpec $OSCustomization -Confirm:$false
}
Ok will try the above script and let u know status..But I dont see any difference between mine and the above script..
Not worked it still giving the same error..David Shall I use the above portion in Guest Customization Part..?
David can you give me the complte script to deploy VMs from template..
This is the core of my script..for making the vms from a template.. My whole provisioning script does alot of other things exclusive to my environment.. So this is the piece I can share...
I
please use only as a template on making your script work... if you chose.
I am by far not a powercli guru like all the others who help out in this forum.. Thanks to great people in this forum, I was able to build exactly what I needed for my environment.
you should be able to understand the variables by the names..
hope it helps...
David
HINT: notice "custemple" I created this PERSISTENT spec on vcenter. It is a one time creation that I just reference in order to build my non-persistent spec called "temp"...
"temp" is the meat and potatoes of it all...
Get-OSCustomizationSpec -Name temp | Remove-OSCustomizationSpec -Confirm:$false
Get-OSCustomizationSpec -Name custemple | New-OSCustomizationSpec -Name temp -Type NonPersistent
Get-OSCustomizationSpec -Name temp | Set-OSCustomizationSpec -Name temp -DnsServer $dns -DnsSuffix $dnsSuffix -Domain $domainname
Get-OSCustomizationSpec -Name temp | Get-OSCustomizationNicMapping |Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress $ip -SubnetMask $subnet -DefaultGateway $gw
New-VM -Name $displayname -OSCustomizationSpec temp -Template ( Get-template $template ) -VMHost $ESXHost -Datastore $datastore
Get-VM -name $displayname | Get-NetworkAdapter | where { $_.Name -eq "Network Adapter 1" } | Set-NetworkAdapter -NetworkName $network -Confirm:$false
Get-vm -Name $displayname | Set-VM -MemoryGB $mem -Confirm:$false
$vm = Get-VM -Name $displayname
$vm | Set-VM -NumCpu ( $cpu ) -Confirm:$false
$vm | New-HardDisk -CapacityGB $HDD1
if ($HDD2 -ne 0) {
$vm | New-HardDisk -CapacityGB $HDD2
}
$vm | Set-VM -Notes $Note -Confirm:$false
Move-VM -VM $displayname -Destination (Get-Folder -Name $folder) -Confirm:$false
Start-VM -VM $displayname
My bad the above one too not working in my Env..
Can you give the complete script you use as well as the error?
When I use the below PowerCLI script to deploy VMs from Template I am getting the below error.
Here is the PowerCLI script:
Import-Csv "C:\Users\sg0217865\Desktop\NewVMs.csv" -UseCulture | %{
Get-OSCustomizationSpec $_.Customization | Get-OSCustomizationNicMapping | `
Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress $_.ip `
-SubnetMask $_.Subnet -DefaultGateway $_.gw
$vm=New-VM -Name $_.Name -Template $_.Template -Host $_.Host `
-Datastore $_.Datastore -Confirm:$false -RunAsync | Set-OSCustomizationSpec -OSCustomizationSpec $_.Customization
}
When I use the below PowerCLI script to deploy VMs from Template I am getting the below error.
Here is the Complete PowerCLI script:
Import-Csv "C:\Users\sg0217865\Desktop\NewVMs.csv" -UseCulture | %{
Get-OSCustomizationSpec $_.Customization | Get-OSCustomizationNicMapping | `
Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress $_.ip `
-SubnetMask $_.Subnet -DefaultGateway $_.gw
$vm=New-VM -Name $_.Name -Template $_.Template -Host $_.Host `
-Datastore $_.Datastore -Confirm:$false -RunAsync | Set-OSCustomizationSpec -OSCustomizationSpec $_.Customization
}
Can you change the following line:
$vm=New-VM -Name $_.Name -Template $_.Template -Host $_.Host `
-Datastore $_.Datastore -Confirm:$false -RunAsync | Set-OSCustomizationSpec -OSCustomizationSpec $_.Customization
into:
$vm=New-VM -Name $_.Name -Template $_.Template -Host $_.Host `
-Datastore $_.Datastore -Confirm:$false -RunAsync | Set-VM -OSCustomizationSpec $_.Customization
See my answer to the other thread where you posted the same question.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The fact that DNS is not mandatory is not an answer. Through the WEB interface you can set the DNS of Customization Specs. Here is about what you CAN or CANNOT do. And it would be nice to be able to do the same things either through CLI or WEB interface.