VMware Cloud Community
StefanSkold
Contributor
Contributor

Changing datastore cluster properties - virtual machine settings

Hello,

I've been trying to find and automated way to make sure ALL my vitual machines are set to Automation Level - Manual in my Datastore Clusters (for StorageDRS). I don't want fullyAutomated and I don't want Default (Manual).

In the GUI it's easy to change by going to Datastores and Datastore Clusters -> properties on a Datastore Cluster -> Virtual Machine Settings -> and set Automation Level for each virtual machine. However, I have thousands of virtual machines and several Datastore Clusters which makes this a tedious work to do manually.

The answer usually lies within PowerCLI and I've created several automated scripts for inventory and management previously. I know how to change advanced settings on virtual machines with .ReconfigVM_Task but have been unable to implement this on my current problem.

I can extract the current values for each virtual machine in the Datastore Cluster with:

(Get-DatastoreCluster <clustername> | Get-View).PodStorageDrsEntry.StorageDrsConfig.VmConfig and I think the object that needs to be created and edited is VMware.Vim.StorageDrsVmConfigInfo.

Since I'm pretty much stuck on this I've been unable to find any other solution. It might be that I'm focusing totally in the wrong direction here... maybe someone can point me in the right direction? Smiley Happy

/Stefan
0 Kudos
5 Replies
LucD
Leadership
Leadership

Try something like this

$dsc = Get-DatastoreCluster MyDSC | Get-View
$storResMgr = Get-View StorageResourceManager 

$spec
= New-Object VMware.Vim.StorageDrsConfigSpec
$spec.podConfigSpec = New-Object VMware.Vim.StorageDrsPodConfigSpec
$spec.podConfigSpec.defaultVmBehavior = "manual"

$storResMgr
.ConfigureStorageDrsForPod($dsc.MoRef,$spec,$true)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
StefanSkold
Contributor
Contributor

First of all, thanks for your time and assistance!

That's not quite what I was looking for though, or maybe I'm just nor reading the settings correctly.

To elaborate on my problem... it happens much to frequently when admins deploy servers that they chose to "Disabled DRS" and manually chose a datatore to place the virtual machine on. When they do this the virtual machine shows up as Disabled in the settings. I'll attach a screenshot to explain what I mean.

storagepod.jpg

I'm trying to find a way to easily change that Disabled or Default (Manual) to Manual as seen in the screenshot.

Sure, it might not seem as a big problem to change that manually but it would be even easier if I could run a script each morning that does this for me Smiley Happy when sometimes I have maybe a hundred servers that have been recently deployed.

/Stefan
0 Kudos
LucD
Leadership
Leadership

I see what you mean. Try it like this

$dsc = Get-DatastoreCluster MyDSC | Get-View 
$storResMgr
= Get-View StorageResourceManager

$spec = New-Object VMware.Vim.StorageDrsConfigSpec
$spec.podConfigSpec = New-Object VMware.Vim.StorageDrsPodConfigSpec
$spec
.podConfigSpec.defaultVmBehavior = "manual"

$storResMgr
.ConfigureStorageDrsForPod($dsc.MoRef,$spec,$false)

The difference is the 2nd parameter. In this case we don't an incremental update of the DatastoreCLuster config, but we replace the complete configuration.

The deault VM setting is configured as "manual", and since we don't pass any individual VM settings they will all fall under the default setting.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

StefanSkold
Contributor
Contributor

Oops!  Running that actually disabled StorageDRS completely on the cluster Smiley Happy when I turned it back on all machines were set to Default (Manual) and the settings I had made for "keep vmdks together" wwere also reset (I have it enabled on some VMs and disabled on others, now it's enabled for all VMs)

I want manual storagedrs so vmware will calculate storage recommendations, but I can chose to implement them myself - ie. not automatically.

Perhaps scripting is not the way to go on this one. The amount of control I want to have might be better achieved with the GUI.

Thanks for your help though, I have learned more on how to configure via powercli and I can implement that on different scenarios in the future Smiley Happy

/Stefan
0 Kudos
Zsoldier
Expert
Expert

To add to LucD‌ responses and your situation.  What you could have done to look to preserve your 'keep vmdks together' options is capture them using the get-datastorecluster cmdlet.

So using LucD's example:

$dsc = get-datastorecluster nameofcluster | get-view

$Rules = $dsc.podstoragedrsentry.storagedrsconfig.vmconfig | where {$_.intravmaffinity -ne $true}

$storResMgr = Get-View StorageResourceManager

$spec = New-Object VMware.Vim.StorageDrsConfigSpec
$spec.podConfigSpec = New-Object VMware.Vim.StorageDrsPodConfigSpec
$spec
.podConfigSpec.defaultVmBehavior = "manual"

$storResMgr
.ConfigureStorageDrsForPod($dsc.MoRef,$spec,$false)

$storResMgr.ConfigureStorageDrsForPod($dsc.MoRef,$Rules,$false)
Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier
0 Kudos