Recently, there was an internal request where the Engineer wanted to change the Datastore Heartbeat Configuration on the HA cluster and he wanted to update the configuration using PowerCLI.
The task was to change the setting to Automatically select the datastores accessible from the hosts. There are three options available in the Web Client and can be seen below:
The same can be done through PowerCLI and the values will be as per the same order:
- allFeasibleDs
- userSelectedDs
- allFeasibleDsWithUserPreference
Therefore, I decided to create PowerCLI functions which will get the current setting and also help you modify the settings and names the functions Get-DatastoreHeartbeatConfig and Set-DatastoreHeartbeatConfig.
Below are the functions and they also accept value from pipeline meaning you can use Get-Cluster cmdlet and pipe these functions to change the settings.
Function Get-DatastoreHeartbeatConfig { [CmdletBinding()] param ( [Parameter( Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] [String[]]$Cluster ) Get-Cluster $Cluster | select Name,@{E={$_.ExtensionData.Configuration.DasConfig.HBDatastoreCandidatePolicy};L="Heartbeat Policy"} } Function Set-DatastoreHeartbeatConfig { [CmdletBinding()] param ( [Parameter( Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] [String[]]$Cluster, [ValidateSet("allFeasibleDs","userSelectedDs","allFeasibleDsWithUserPreference")] [String[]]$Option ) $Spec = New-Object VMware.Vim.ClusterConfigSpecEx $Spec.DasConfig = New-Object VMware.Vim.ClusterDasConfigInfo $ClusterName = Get-Cluster $Cluster if ($Option -eq "allFeasibleDs"){ $Spec.DasConfig.HBDatastoreCandidatePolicy = "allFeasibleDs" $ClusterName.ExtensionData.ReconfigureComputeResource_Task($Spec, $true) } elseif ($Option -eq "userSelectedDs"){ $Datastores = Get-Datastore | Out-Gridview -Title "Select only two datastores" -Passthru $Spec.dasConfig.heartbeatDatastore = New-Object VMware.Vim.ManagedObjectReference[](2) $Spec.dasConfig.heartbeatDatastore[0] = New-Object VMware.Vim.ManagedObjectReference $Spec.dasConfig.heartbeatDatastore[0].type = "Datastore" $Spec.dasConfig.heartbeatDatastore[0].Value = $Datastores[0].ExtensionData.MoRef.Value $Spec.dasConfig.heartbeatDatastore[1] = New-Object VMware.Vim.ManagedObjectReference $Spec.dasConfig.heartbeatDatastore[1].type = "Datastore" $Spec.dasConfig.heartbeatDatastore[1].Value = $Datastores[1].ExtensionData.MoRef.Value $Spec.DasConfig.HBDatastoreCandidatePolicy = "userSelectedDs" $ClusterName.ExtensionData.ReconfigureComputeResource_Task($Spec, $true) } elseif ($Option -eq "allFeasibleDsWithUserPreference"){ $Datastores = Get-Datastore | Out-Gridview -Title "Select only two datastores" -Passthru $Spec.dasConfig.heartbeatDatastore = New-Object VMware.Vim.ManagedObjectReference[](2) $Spec.dasConfig.heartbeatDatastore[0] = New-Object VMware.Vim.ManagedObjectReference $Spec.dasConfig.heartbeatDatastore[0].type = "Datastore" $Spec.dasConfig.heartbeatDatastore[0].Value = $Datastores[0].ExtensionData.MoRef.Value $Spec.dasConfig.heartbeatDatastore[1] = New-Object VMware.Vim.ManagedObjectReference $Spec.dasConfig.heartbeatDatastore[1].type = "Datastore" $Spec.dasConfig.heartbeatDatastore[1].Value = $Datastores[1].ExtensionData.MoRef.Value $Spec.DasConfig.HBDatastoreCandidatePolicy = "allFeasibleDsWithUserPreference" $ClusterName.ExtensionData.ReconfigureComputeResource_Task($Spec, $true) } }
The function currently accepts only two datastores as part of the User preference. Something that I think can be enhanced in the near future.
Now, let is go ahead and see this action. First, we will use the Get-DatastoreHeartbeatConfig to see the current Datastore Heartbeat Configuration.
Get-DatastoreHeartbeatConfig -Cluster Bangalore
OR
Get-Cluster Bangalore | Get-DatastoreHeartbeatConfig
Next, let us change the current configuration to User Selected Datastores.
Set-DatastoreHeartbeatConfig -cluster Bangalore -Option userSelectedDs
OR
Get-Cluster Bangalore | Set-DatastoreHeartbeatConfig -Option userSelectedDs
Once the function starts to execute, you will see a window which will ask you to select two datastores as seen below:
Click OK and the changes should take effect. You can also verify by going to the Cluster configuration again.
I hope this has been informative and thank you for reading!