This script works without errors, but all parameters (IPs, DNS, passwords) remain untouched
$masterName = "Server"
$snapName = "Master"
$dsName = "Stor01"
$rpName = "DPool"
$oscustName = "Easy"
# Create a non-persistent copy
$oscust = Get-OSCustomizationSpec -Name $oscustName
$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 -ErrorAction Stop
}
Catch {
$snap = New-Snapshot -Name $snapName -VM $vm
}
# Create the linked clones
Import-Csv C:\scripts\ed.csv -UseCulture | %{
# Configure NIC settings
$nicParams = @{
IpMode = "UseStaticIP"
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-OSCustomizationSpec $oscust |
Set-OSCustomizationSpec @osParams
# Create linked clone
$cloneParams = @{
Name = $_.Name
VM = $vm
ReferenceSnapshot = $snap
LinkedClone = $true
ResourcePool = $rpName
Datastore = $dsName
OSCustomizationSpec = $osSpec
}
New-VM @cloneParams
Start-VM $_.Name
}