Hello,
Attached is script that I have been using to create virtual machines and it works fine when the VMs are being created to single datastores but doesn't like clustered datastores. I think the reason is that it creates the VM through the esx host (which doesn't know about the cluter) and not through vCenter (which does know about it.) Unfortunately I don't know how to rectify it.
Thanks,
Astra
Looks like it needs a datastore object for that parameter. So, we need to do a get Datastore cluster I can try to test tomorrow, but try this:
If ($datastore1 -ne "none") {
$drscluster = Get-DatastoreCluster $datastore1
$vmadddsk = New-HardDisk -VM $gstname -CapacityKB $datastore1size -DataStore $drscluster
}
Is the datastorecluster perhaps configured to have the VMs in "fully automated" ?
And what is the error message you get ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The SDRS automation is set to Manual mode, no automation. The error message is that the datastore I am pointing to (the name of the datastore cluster) does not exist.
What are you connecting to when running your script are you connecting to Vcenter or host?
Coudl have something to do with there is a default affinity rule to keep disks together in SDRS cluster?
Are you trying to have the disks go to a different datastore than the first hard disk? Why do you need 2 datastore variables if going to a SDRS cluster?
http://www.vmware.com/support/developer/PowerCLI/PowerCLI51R2/html/index.html
-------------- Example 5 --------------
$vm = Get-VM WebServerVM $disk = $vm | Get-HardDisk $antiAffinityRule = New-Object 'VMware.VimAutomation.ViCore.Types.V1.DatastoreManagement.SdrsVMDiskAntiAffinityRule' $disk New-HardDisk -VM $vm -AdvancedOption $antiAffinityRule -CapacityGB 40 -Datastore DatastoreCluster1
First retrieves the existing disk which will be part of the VMDK anti affinity rule. Then, creates an object describing the rule and creates the new hard disk.
I am connecting to the vCenter through the vsphere cli (connect-vihost and the name) when I am running the script.
There are no affinity rules.
The primary disk is going to the OS datastore. The SDRS cluster is the 2nd datastore which is for the data volumes of the VMs.
I tried your example but it still says that the datastore (name of the SDRS cluster) does not exist.
Thanks for the help to figure this out.
Connect to your vcenter and not the host. The script should still work
connect-viserver vcenter
and not
connect-vihost
Sorry that a was a mispell, connect-viserver is the one I am using.
Looks like it needs a datastore object for that parameter. So, we need to do a get Datastore cluster I can try to test tomorrow, but try this:
If ($datastore1 -ne "none") {
$drscluster = Get-DatastoreCluster $datastore1
$vmadddsk = New-HardDisk -VM $gstname -CapacityKB $datastore1size -DataStore $drscluster
}
markdjones82 thanks for the help, when the Get-DatastoreCluster was not recognized I realized that's something not right, so I looked and I was on 4.1 cli :smileyplain: Anyhow, when I upgraded to 5.1 everything worked, so thanks all for your help.
Excellent, that was going to be my next suggestion. So did the original script work once you upgraded the powercli or did you have to get the datastore cluster object first?
The original script worked fine when I upgraded the powercli, 4.1 was too young to know about sdrds hehe. Thanks again for the help.