Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 230663

Re: How to script deploying from template or making Clones

$
0
0

Sure, try something like this

$masterName="Server001"
$snapName="Master"
$esxName="MyEsx"
$oscustName="Your OSCustomizationSpec"

# Create a non-persistent copy
$oscust=Get-OSCustomizationSpec-Name$oscustName|New-OSCustomizationSpec-TypeNonPersistent
$vm=Get-VM-Name$masterName

# Get the snapshot
if($vm.PowerState-eq"PoweredON"){
 
"Master VM $vmName needs to be powered off"
 
return
}
Try {
 
$snap=Get-Snapshot-Name$snapName-VM$vm-ErrorActionStop
}
Catch {
 
$snap=New-Snapshot-Name$snapName-VM$vm
}

# Create the linked clones
Import-CsvC:\lclones.csv-UseCulture|%{
 
# Configure NIC settings
  $nicParams=@{
   
IPMode= "Static"
   
IPAddress=$_.IP
   
SubnetMask=$_.Mask
   
DefaultGateway=$_.Gateway
   
Dns=@($_.Dns)
  }
 
Get-OSCustomizationNicMapping-OSCustomizationSpec$oscust|
 
Set-OSCustomizationNicMapping$nicParams

 
# Set admin password
  $osParams=@{
   
AdminPassword=$_.Password
   
NamingScheme= "Fixed"
   
NamingPrefix=$_.Name
  }
 
Get-OSCustomizationNicMapping-OSCustomizationSpec$oscust|
 
Set-OSCustomizationSpec@osParams

 
# Create linked clone
  $cloneParams=@{
   
Name=$_.Name
   
VM=$vm
   
ReferenceSnapshot=$snap
   
LinkedClone=$true
   
VMHost=$esxName
   
OSCustomizationSpec=$osSpec
  }
 
New-VM@cloneParams
}

Your CSV file should look like this

 

Name,IP,Mask,Gateway,Dns,Password

VM1,192.168.1.1,255.255.255.0,193.168.1.254,DNS1,MyPswd


Viewing all articles
Browse latest Browse all 230663

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>