Ouch well i think i broke something.... First off if i am annoying just say so a co-worker of mine started with the script and he is on holiday now, i had some time extra and wanted to learn 'scripting' as well seeing how powerfull it can ben.
This is the full script, the idea is to have the 'master'-replica image on SSD storage, and have the delta's in the selected storage cluster which is picked at the $datastroreclustername...
When i hardcoded the storagecluster in the file it works.
But with the selection part i had to move the variables to the top of the script. if i didn't do that i had to select for every VM which cluster and which storagecluster.
If i am saying nonsense sorry
Arrghh i can't get the layout to work.... but also attached the file.
Connect-VIServer"vcenter.local"$sourceVM=Get-VM"test-replica" | Get-View$AgentTotal=Read-Host-Prompt"Enter total agent number"$totalXPCount= (Get-VM-Name uams* | Measure-Object).Count #Hier word de keuze voor het host cluster gevraagd. $Cluster=Get-Cluster $CLuster | ForEach-Object-begin {$i=0} -process { "$i. $($Cluster[$i].Name)" $i++ } $ClusterNumber=Read-Host-Prompt"Enter cluster number" $Cluster[$ClusterNumber] #Hier word de keuze voor het storage cluster gevraagd. $datastoreclustername=Get-DatastoreCluster $datastoreclustername | ForEach-Object-begin {$i=0} -process { "$i. $($datastoreclustername[$i].Name)" $i++ } $ClusterNumber1=Read-Host-Prompt"Enter Datstorecluster number" $datastoreclustername[$ClusterNumber1]if($totalXPCount-lt$agentTotal){ for($adt=$totalXPCount+1; $adt-le$agentTotal; $adt++){ #Naam sequentie voor de nieuwe vm's $cloneName="test{0:0##}"-f ($adt+10) #$cloneName = "test01" $cloneFolder=$sourceVM.parent foreach ($vmin$cloneName){ $cloneSpec=new-objectVmware.Vim.VirtualMachineCloneSpec $cloneSpec.Snapshot=$sourceVM.Snapshot.CurrentSnapshot $cloneSpec.Location=new-objectVmware.Vim.VirtualMachineRelocateSpec $cloneSpec.Location.DiskMoveType= [Vmware.Vim.VirtualMachineRelocateDiskMoveOptions]::createNewChildDiskBacking $cloneSpec.Location.Host= (Get-Cluster-Name$cluster).MoRef $cloneSpec.Location.Datastore= (Get-DatastoreCluster-Name $datastoreclustername).Extensiondata.MoRef $cloneSpec.customization=New-ObjectVMware.Vim.CustomizationSpec $cloneSpec.customization.options=New-ObjectVMware.Vim.CustomizationWinOptions $cloneSpec.customization.options.changeSID =$true $cloneSpec.customization.options.deleteAccounts =$true $cloneSpec.customization.identity=New-ObjectVMware.Vim.CustomizationSysprep $cloneSpec.customization.identity.guiUnattended =New-ObjectVMware.Vim.CustomizationGuiUnattended $cloneSpec.customization.identity.guiUnattended.password =New-ObjectVMware.Vim.CustomizationPassword $cloneSpec.customization.identity.guiUnattended.password.value ="verysecretpassword" $cloneSpec.customization.identity.guiUnattended.password.plainText =$true $cloneSpec.customization.identity.guiUnattended.timeZone =110 $cloneSpec.customization.identity.guiUnattended.autoLogon =$false $cloneSpec.customization.identity.guiUnattended.autoLogonCount =0 $cloneSpec.customization.identity.userData =New-ObjectVMware.Vim.CustomizationUserData $cloneSpec.customization.Identity.userData.productId ="" $cloneSpec.customization.identity.userData.fullName ="name" $cloneSpec.customization.identity.userData.orgName ="name" $cloneSpec.customization.identity.userData.computerName =New-ObjectVMware.Vim.CustomizationFixedName $cloneSpec.customization.identity.userData.computerName.Name =$cloneName $cloneSpec.customization.identity.identification =New-ObjectVMware.Vim.CustomizationIdentification $cloneSpec.customization.identity.identification.domainAdmin ="domain" $cloneSpec.customization.identity.identification.domainAdminPassword =New-ObjectVMware.Vim.CustomizationPassword $cloneSpec.customization.identity.identification.domainAdminPassword.plaintext =$true $cloneSpec.customization.identity.identification.domainAdminPassword.value ="blaat" $cloneSpec.customization.identity.identification.JoinDomain ="supersecret.local" $cloneSpec.customization.globalIPSettings=New-ObjectVMware.Vim.CustomizationGlobalIPSettings #$cloneSpec.customization.globalIPSettings.dnsSuffixList = New-Object System.String[] (1) #$cloneSpec.customization.globalIPSettings.dnsSuffixList[0] = "" $cloneSpec.customization.nicSettingMap=New-ObjectVMware.Vim.CustomizationAdapterMapping[] (2) $cloneSpec.customization.nicSettingMap[0] =New-ObjectVMware.Vim.CustomizationAdapterMapping $cloneSpec.customization.nicSettingMap[0].adapter =New-ObjectVMware.Vim.CustomizationIPSettings $cloneSpec.customization.nicSettingMap[0].adapter.ip =New-ObjectVMware.Vim.CustomizationDhcpIpGenerator $cloneSpec.customization.nicSettingMap[1] =New-ObjectVMware.Vim.CustomizationAdapterMapping $cloneSpec.customization.nicSettingMap[1].adapter =New-ObjectVMware.Vim.CustomizationIPSettings $cloneSpec.customization.nicSettingMap[1].adapter.ip =New-ObjectVMware.Vim.CustomizationDhcpIpGenerator #$cloneSpec.powerOn = $true Write-Host$cloneName-foregroundcolorcyan $vm=$sourceVM.CloneVM_Task($cloneFolder, $cloneName, $cloneSpec) } } }