AstraMonti
Enthusiast
Enthusiast

Script to create VMs fails when trying to add disk on datastore cluster

Jump to solution

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

0 Kudos
1 Solution

Accepted Solutions
markdjones82
Expert
Expert

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           

    }

http://www.twitter.com/markdjones82 | http://nutzandbolts.wordpress.com

View solution in original post

0 Kudos
10 Replies
LucD
Leadership
Leadership

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

AstraMonti
Enthusiast
Enthusiast

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.

0 Kudos
markdjones82
Expert
Expert

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.

http://www.twitter.com/markdjones82 | http://nutzandbolts.wordpress.com
AstraMonti
Enthusiast
Enthusiast

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.

0 Kudos
markdjones82
Expert
Expert

Connect to your vcenter and not the host.  The script should still work

connect-viserver vcenter

and not

connect-vihost

http://www.twitter.com/markdjones82 | http://nutzandbolts.wordpress.com
0 Kudos
AstraMonti
Enthusiast
Enthusiast

Sorry that a was a mispell, connect-viserver is the one I am using.

0 Kudos
markdjones82
Expert
Expert

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           

    }

http://www.twitter.com/markdjones82 | http://nutzandbolts.wordpress.com

View solution in original post

0 Kudos
AstraMonti
Enthusiast
Enthusiast

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.

0 Kudos
markdjones82
Expert
Expert

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?

http://www.twitter.com/markdjones82 | http://nutzandbolts.wordpress.com
0 Kudos
AstraMonti
Enthusiast
Enthusiast

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.

0 Kudos