1 2 Previous Next 22 Replies Latest reply on Oct 2, 2017 9:59 AM by luckyinfil21

    changing vm storage drs automation level

    Onthax Novice

      As per http://communities.vmware.com/message/2172311#2172311

       

      I'm using LucD's method, to extract a list of vm's that have vm's turned on

       

      function Get-StoragePod{
      <#
      .SYNOPSIS  Find a DatastoreCluster
      .DESCRIPTION The function will return a StoragePod object.
        This is the server-side object used by vSphere for a  DatastoreCluster.
      .NOTES  Author:  Luc Dekens
      .PARAMETER Name  The name of the DatastoreCluster
      .EXAMPLE
        PS> Get-StoragePod
      .EXAMPLE
        PS> Get-StoragePod -Name "SDC*"
      #>
        param(
        [CmdletBinding()]
        [parameter(Position = 0, ValueFromPipeline = $true)]
        [string]$Name = "*"  )
        begin{
         function Get-StoragePodInternal{
           param(
           [CmdletBinding()]
           [parameter(Mandatory = $true,ValueFromPipeline = $true)]
           [VMware.Vim.Folder]$Folder     )
           $Folder.ChildEntity | %{
             if($_.Type -eq "StoragePod"){
               Get-View -Id $_       }
             elseif($_.Type -eq "Folder"){
               Get-View -Id $_ | Get-StoragePodInternal
             }
           }
          }
        }
        process{
          Get-Folder -Name datastore | %{
            Get-StoragePodInternal -Folder $_.ExtensionData
          } | where {$_.Name -like $Name}
        }
      }
      $dsc = Get-StoragePod -Name $datastorecluster
      $vmlist = $dsc.PodStorageDrsEntry.StorageDrsConfig.VmConfig | where {$_.Enabled -notmatch "False"} | Select @{N="VM";E={(Get-View $_.VM).Name}},Enabled,IntraVmAffinity | where {$_.VM -like "*_replica"}

       

      This successfully gets a list of vm's that have sdrs enabled that shouldnt.

       

      I'm struggling with how to disable sdrs.  I'm new to powershell

       

      from what i can gather i need to update dsc.podstoragedrsentry.storagedrsconfig.vmconfig.enabled to False.

       

      but i'm unsure how to do this, or could point me in the right direction?

        • 1. Re: changing vm storage drs automation level
          LucD Guru
          Community WarriorsvExpertUser Moderators

          You will have to use the ConfigureStorageDrsForPod_Task method to change the settings for SDRS.

          In the StorageDrsConfigSpec object you can disable this.

          Combined with your Where-clause this could be something like this

           

           

          $storMgr = Get-View StorageResourceManager
          
          $pod
          = Get-DatastoreCluster -Name $datastorecluster
          $spec
          = New-Object VMware.Vim.StorageDrsConfigSpec $pod.ExtensionData.PodStorageDrsEntry.StorageDrsConfig.VmConfig | where {(Get-View $_.VM | Select -ExpandProperty Name) -like "*_replica"} | %{   $entry = New-Object VMware.Vim.StorageDrsVmConfigSpec
            $entry.Operation = "edit"
            $entry.Info = $_
           
          $entry.Info.Enabled = $false
            $spec.vmConfigSpec += $entry
          } $storMgr.ConfigureStorageDrsForPod($pod.ExtensionData.MoRef,$spec,$true)

           

          Note that the Get-DatastoreCluster cmdlet can be used to replace my function

          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          • 2. Re: changing vm storage drs automation level
            Onthax Novice

            Cheers Mate!

             

            That's just what i needed, need to learn a bit more powershell to fully follow how to replicate how you did this but thanks :^)

            • 3. Re: changing vm storage drs automation level
              LucD Guru
              User ModeratorsvExpertCommunity Warriors

              As a matter of fact this is PowerShell/PowerCLI using one the SDK API to change the settings.

              Not all vSphere API are available through PowerCLI cmdlets, but it is quite easy to call the SDK API directly from within PowerCLI/PowerShell.

              Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
              1 person found this helpful
              • 4. Re: changing vm storage drs automation level
                Onthax Novice

                This script seemed to be working as expected, but recently I noticed that New VM's that are added to the datastore cluster won't appear when you run $pod.ExtensionData.PodStorageDrsEntry.StorageDrsConfig.VmConfig

                 

                I haven't been able to get them detected and working, Does anyone know if there is anything that needs to be done after adding a vm to have it appear from powercli when looking at members of a SDRS cluster?

                • 5. Re: changing vm storage drs automation level
                  LucD Guru
                  vExpertUser ModeratorsCommunity Warriors

                  I suspect that the new information is not present.

                  Remember that the objects you get in PowerCLI are read-only copies.

                  You can force a refresh with

                  $pod.ExtensionData.UpdateViewData()

                  Does that help ?

                  Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                  • 6. Re: changing vm storage drs automation level
                    Onthax Novice

                    Thanks for the quick response LucD

                    No luck,

                     

                    Ran $pod.ExtensionData.UpdateViewData() then  $pod.ExtensionData.PodStorageDrsEntry.StorageDrsConfig.VmConfig

                    the new VM won't show in powercli, however shows fine in GUI

                     

                    Any idea on how often it refreshes?

                    • 7. Re: changing vm storage drs automation level
                      LucD Guru
                      Community WarriorsUser ModeratorsvExpert

                      The PowerCLI object does not refresh, unless you do an UpdateViewData.

                      Did you try fetching the datastorecluster object again

                       

                      $pod = Get-DatastoreCluster -Name $datastorecluster

                      Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                      • 8. Re: changing vm storage drs automation level
                        Cruckman4 Lurker

                        I'm having the same problem where newly added VMs to the datastore cluster failed to show up in ~StorageDrsConfig.VmConfig.  One way I've found to get them to show up is to enable/disable storage DRS from vSphere Client on the datastore cluster.  For some reason, after doing that from the vSphere GUI, the VMs show up then in ~StorageDrsConfig.VmConfig.  I tried using Set-DatastoreCluster to change the sdrsautomationlevel to manual / disabled, but no luck in getting the VMs to show up.  So far, only after editing the datastore cluster settings from vSphere client.  Not sure if it might be an issue with the vCenter Server not passing the information along or what.  I'd be curious to know what versions you're using.  I'm using ESXi 5.1U1, vCenter Server 5.1U1, and PowerCLI 5.1 release 1.

                        • 9. Re: changing vm storage drs automation level
                          LucD Guru
                          Community WarriorsUser ModeratorsvExpert

                          The changes you make in vCenter are not automatically done in your PowerCLI variables.

                          You will have to get the object again, or refresh the ExtensionData property with the UpdateViewData method.

                          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                          • 10. Re: changing vm storage drs automation level
                            Cruckman4 Lurker

                            Sorry, forgot to mention that I re-fetched the datastore cluster object after adding VMs to it, and also after changing the sdrsautomationlevel with Set-DatastoreCluster. Unfortunately, it still had nothing in ~.StorageDrsConfig.VmConfig.  Only after making the changes in vCenter and getting the object again after making the changes did the VMs finally show up in ~.StorageDrsConfig.VmConfig.

                            • 11. Re: changing vm storage drs automation level
                              LucD Guru
                              vExpertUser ModeratorsCommunity Warriors

                              The ExtensionData property is handled a bit differently, compared to regular PowerShell variables and their properties.

                              Did you also try with the UpdateViewData method as I suggested ?

                              It might be a caching problem.

                              Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                              • 12. Re: changing vm storage drs automation level
                                Cruckman4 Lurker

                                Yeah, I tried that too to no avail

                                • 13. Re: changing vm storage drs automation level
                                  LucD Guru
                                  vExpertUser ModeratorsCommunity Warriors

                                  I'll check if I can reproduce that

                                  Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                                  • 14. Re: changing vm storage drs automation level
                                    Onthax Novice

                                    Hi LucD

                                     

                                    I tried $pod.ExtensionData.PodStorageDrsEntry.StorageDrsConfig.VmConfig

                                    then

                                    $pod.ExtensionData.UpdateViewData()

                                    then

                                    $pod = Get-DatastoreCluster -Name $datastorecluster

                                    The VM still doesnt appear when I do a $pod.ExtensionData.PodStorageDrsEntry.StorageDrsConfig.VmConfig

                                    VM was added more than a week ago, so it doesnt seem to be an internal refresh timer.

                                    1 2 Previous Next