Been a while since I posted, so about time I caught up with some things I have been working on!
I will be posting a series of PowerCLI / Powershell cmdlets to assist with vSAN Day-2 operations. There is plenty out there for creating new clusters, but not much around for helping to troubleshoot / support production environments. Some of these have come from VMworld Europe Hackathon I recently attended in Europe which was a blast! I’ll do my best to credit others who helped contribute to the creation of these cmdlets also!
The first I created Get-VSANObjectHealth is to help obtain a state of the objects in a vSAN cluster. This is a great way to validate how things are in the environment, as it will give you the different status of objects, particularly if they are degraded or rebuilding. The idea of this cmdlet was to integrate into our host remediation script so I could verify that all the objects are healthy prior to moving onto the next host. I trust this verification in PowerCLI more so than VUM attempting to put a host into maintenance and then getting stuck.
Code is below and also posted on GitHub Here
Function Get-VSANObjectHealth {
<#
.SYNOPSIS
Obtain object health for vSAN Cluster
.DESCRIPTION
This function performs an object health report for a vSAN Cluster
.PARAMETER VsanCluster
Specifies a vSAN Cluster object, returned by Get-Cluster cmdlet.
.EXAMPLE
PS C:\> Get-Cluster | Get-VSANObjectHealth
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory, ValueFromPipeline)]
[Alias("Cluster")]
[VMware.VimAutomation.ViCore.Types.V1.Inventory.Cluster]$VsanCluster
,
[Parameter(Mandatory = $false)]
[switch]$ShowObjectUUIDs
,
[Parameter(Mandatory = $false)]
[switch]$UseCachedInfo
,
[Parameter(Mandatory = $false)]
[switch]$HealthyOnly
)
Begin {
$vchs = Get-VsanView -Id "VsanVcClusterHealthSystem-vsan-cluster-health-system"
$VsanVersion = (Get-VsanView -Id "VsanVcClusterHealthSystem-vsan-cluster-health-system").VsanVcClusterQueryVerifyHealthSystemVersions((Get-Cluster).Id) | select VcVersion
}
Process {
if($VsanCluster.VsanEnabled -and $VsanVersion.VcVersion -lt '6.6') {
$result = $vchs.VsanQueryVcClusterHealthSummary($VsanCluster.id, $null, $null, $ShowObjectUUIDs, $null, $UseCachedInfo)
if($result) {
if($HealthyOnly) {
$Health = $result.ObjectHealth.ObjectHealthDetail | Where-Object {$_.Health -notlike 'healthy' -and $_.NumObjects -gt 0}
if($Health) {
return $false
} else {
return $true
}
} else {
return $result.ObjectHealth.ObjectHealthDetail
}
}
}
elseif ($VsanCluster.VsanEnabled -and $VsanVersion.VcVersion -lt '6.6') {
Write-Warning -Message 'vSAN cluster is currently at a version newer than this call allows. Please open an issue: https://github.com/mitsumaui/PowerTheVSAN/issues'
}
}
}
How to use:
Get-Cluster VSAN-Cluster-1 | Get-VSANObjectHealth
Get-Cluster VSAN-Cluster-1 | Get-VSANObjectHealth -HealthyOnly
Get-Cluster VSAN-Cluster-1 | Get-VSANObjectHealth -ShowObjectUUIDs
Details on the Switches:
– HealthyOnly
Will only return True if all objects are healthy, else will return False
– ShowObjectUUIDs
Will extend the query to include an array of ObjectUUIDs for each health category. Good if you need to investigate specific objects
– UseCachedInfo
Will use the cached vSAN Health data from the vCenter server rather than forcing an update from the cluster. Great if you need a quick check, but not recommended if you need a current picture of object health (such as just after exiting from Maintenance Mode)
Enjoy and please do let me know (either via comments here or GitHub) if there is any other enhancements you would like to see! More cmdlets to come soon.