5 Replies Latest reply on Feb 18, 2016 7:10 AM by Zsoldier

    Changing datastore cluster properties - virtual machine settings

    StefanSkold Novice

      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?

        • 1. Re: Changing datastore cluster properties - virtual machine settings
          LucD Guru
          vExpertCommunity WarriorsUser Moderators

          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: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          • 2. Re: Changing datastore cluster properties - virtual machine settings
            StefanSkold Novice

            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 when sometimes I have maybe a hundred servers that have been recently deployed.

            • 3. Re: Changing datastore cluster properties - virtual machine settings
              LucD Guru
              vExpertUser ModeratorsCommunity Warriors

              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: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
              1 person found this helpful
              • 4. Re: Changing datastore cluster properties - virtual machine settings
                StefanSkold Novice

                Oops!  Running that actually disabled StorageDRS completely on the cluster 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

                • 5. Re: Changing datastore cluster properties - virtual machine settings
                  Zsoldier Expert
                  vExpert

                  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)