VMware Cloud Community
Onthax
Contributor
Contributor
Jump to solution

changing vm storage drs automation level

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?

Reply
0 Kudos
22 Replies
jesse_gardner
Enthusiast
Enthusiast
Jump to solution

Couple things here- The reason you're getting an error is because you're setting the Info properties to empty strings, which is different than null.  Empty string is an invalid value.

But I was unable to get it to say "Default" with the "Edit" operation.  I could set it to "Fully Automated" by (info.behavior="automated" and info.enabled=$true), but that isn't exactly what you wanted.  Setting them to $null didn't work as I expected.

But it seems that the "Add" operation instead of "Edit" will overwrite the existing configuration for a given VM, allowing you to get back to defaults.

I think this should get you what you want:

$storMgr = Get-View StorageResourceManager              
$spec = New-Object VMware.Vim.StorageDrsConfigSpec              
$dsc = Get-Datastorecluster DS1             
get-vm -Datastore $dsc |%{              
    $vmEntry = New-Object VMware.Vim.StorageDrsVmConfigSpec            
    $vmEntry.Operation = "add"            
    $vmEntry.Info = New-Object VMware.Vim.StorageDrsVmConfigInfo            
    $vmEntry.Info.Vm = $_.ExtensionData.MoRef            
    $spec.vmConfigSpec += $vmEntry             
}              
$storMgr.ConfigureStorageDrsForPod($dsc.ExtensionData.MoRef,$spec,$true)
Reply
0 Kudos
cans
Contributor
Contributor
Jump to solution

It's exactly what I want and it works perfectly ! Smiley Happy

Thanks !

Reply
0 Kudos
luckyinfil21
Contributor
Contributor
Jump to solution

Not sure if this was ever figured out, but you can build out the same objects using Get-Datastore | Get-VM instead of grabbing the list of VMs from the datastore cluster settings which appears to have issues. The altered code is below:

$pod | Get-VM | Where-Object {$_.Name -like "*volume*"} |

%{

  $_.Name

  $entry = New-Object VMware.Vim.StorageDrsVmConfigSpec

  $entry.Info = New-Object VMware.Vim.StorageDrsVmConfigInfo

  $entry.Operation = "edit"

  $entry.Info.VM = $_.ExtensionData.MoRef

  $entry.Info.Enabled = $false

  $spec.vmConfigSpec += $entry

}

Reply
0 Kudos