No, you can't use a cluster afaik, but you can pick a random node from a cluster.
Datastore can be specified. In the below script I assume it is picked up from the CSV file.
The Fixed and Static values had to be between quotes.
Do you have a OSCustomizationSPec defined ? Change the name to reflect your spec !
Try again with this updated version
$masterName="Server001"
$snapName="Master"
$clusterName="MyCluster"
$esx=Get-Cluster-Name$clusterName|Get-VMHost|Get-Random
$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=$esx
Datastore=$_.Datastore
OSCustomizationSpec=$osSpec
}
New-VM@cloneParams
}