Deploy Virtual Machine In Vsphere – As Static or DHCP IP Address-VMware PowerCLI,

Deploy Virtual Machine in VSphere- via Static IP or DHCP by script in VMware PowerCLI,

virtualmachine

 Prerequisites Requirements

  • Virtual Machine Windows Template
  • VMware Customization Wizard Profile.
  • IP Address
  • Subnet
  • Gateway

Deploy Virtual Machine with specific Static IP Address.

powercli

deplolyviastaticip

deployfromstatic

csvdeployfromtemplate

Core Script Method= Set-OSCustomizationNicMapping -IpMode UseStaticIp
‘Modifying the customization file with the network information you specified in the CSV’
  Get-OSCustomizationSpec $Customization | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIp -IpAddress $IPAddress -SubnetMask $Subnetmask -DefaultGateway $DefaultGW

Core Script Method= Set-OSCustomizationNicMapping -IpMode DHCP
Get-OSCustomizationSpec $Customization | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode

Powercli Code Sample

‘Beginning Script’
‘Loading Snapins’
function LoadSnapin{
param($PSSnapinName)
if (!(Get-PSSnapin | where {$_.Name   -eq $PSSnapinName})){
Add-pssnapin -name $PSSnapinName
}
}
LoadSnapin -PSSnapinName   “VMware.VimAutomation.Core”
‘Reading CSV file’
$vms = Import-CSV C:\Users\richard\Documents\newvms1.csv
‘Reading the contents of the CSV, and for each line execute the following code’
foreach ($vm in $vms){
‘Declaring variables that correspond to the column names in the CSV’
$VMName = $vm.name
$VMHost = Get-VMHost $vm.host
$Datastore = Get-Datastore $vm.datastore
$Template = Get-Template $vm.template
$Customization = $vm.customization
$IPAddress = $vm.ipaddress
$Subnetmask = $vm.subnetmask
$DefaultGW = $vm.defaultgw
$DNS1 = $vm.dns1
$DNS2 = $vm.dns2
# $WINS1 = $vm.wins1
# $WINS2 = $vm.wins2’Modifying the customization file with the network information you specified in the CSV’
Get-OSCustomizationSpec $Customization | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIp -IpAddr
 ‘VMWare Automated Template Deployment Script
Script and Code was borrowed from the following smart people to help with learning journey.
Luc Dekens, Vmware blog.
Powershell and Linux OS Deploy Virtual Machine via Powershell DSC Linux -Coming Soon!!!!

redhatUbuntulogosuse

References:

  1. Great Video Tutorial Overview of Using Templates and Clone methods in Vsphere. 

2. VMware Technology Network

3. vSphere PowerCLI Cmdlets Reference Get-OSCustomizationSpec

4. Working with Customization Specifications in PowerCLI

5. Powershell and Linux Integration

6. Deploying a VM with Static IP in 3 Steps

7. Deploy Linux VM via PowerCLI.


Leave a Reply

Your email address will not be published. Required fields are marked *