# Import VMware PowerCLI module
Import-Module VMware.VimAutomation.Core

# Connect to vCenter
$vCenter = Read-Host "Enter vCenter Server"
$Username = Read-Host "Enter vCenter Username"
$Password = Read-Host -AsSecureString "Enter vCenter Password"
Connect-VIServer -Server $vCenter -User $Username -Password $Password

# Function to retrieve failed vSAN components
function Get-FailedVSANComponents {
    # Get all vSAN clusters
    $clusters = Get-Cluster | Where-Object { $_.VsanEnabled -eq $true }

    foreach ($cluster in $clusters) {
        Write-Output "Checking vSAN Cluster: $($cluster.Name)"

        # Retrieve vSAN disk groups
        $vsanDiskGroups = Get-VsanDiskGroup -Cluster $cluster

        foreach ($diskGroup in $vsanDiskGroups) {
            Write-Output "Disk Group on Host: $($diskGroup.VMHost)"

            # Retrieve disks in the disk group
            $disks = $diskGroup.Disk

            foreach ($disk in $disks) {
                # Check if the disk is in a failed state
                if ($disk.State -eq "Failed" -or $disk.Health -eq "Failed") {
                    Write-Output "  Failed Disk Found: $($disk.Name)"
                    Write-Output "  Capacity Tier Disk? $($disk.IsCapacity)"
                    Write-Output "  Disk UUID: $($disk.VsanDiskId)"
                    Write-Output "  Disk Group UUID: $($diskGroup.VsanDiskGroupId)"

                    # Check which vSAN component(s) this disk was part of
                    $vsanComponents = Get-VsanObject -Cluster $cluster | Where-Object {
                        $_.PhysicalDisk.Uuid -eq $disk.VsanDiskId
                    }

                    foreach ($component in $vsanComponents) {
                        Write-Output "    vSAN Component: $($component.Uuid)"
                        Write-Output "    Associated VM: $($component.VMName)"
                        Write-Output "    Object State: $($component.State)"
                    }
                }
            }
        }
    }
}

# Run the function
Get-FailedVSANComponents

# Disconnect from vCenter
Disconnect-VIServer -Confirm:$false

Output Example

Checking vSAN Cluster: Cluster01
Disk Group on Host: esxi-host01
  Failed Disk Found: naa.6000c2929b23abcd0000000000001234
  Capacity Tier Disk? True
  Disk UUID: 52d5c239-1aa5-4a3b-9271-d1234567abcd
  Disk Group UUID: 6e1f9a8b-fc8c-4bdf-81c1-dcb7f678abcd
    vSAN Component: 8e7c492b-7a67-403d-bc1c-5ad4f6789abc
    Associated VM: VM-Database01
    Object State: Degraded

Customization

  • Modify $disk.State or $disk.Health conditions to filter specific states.
  • Extend the script to automate remediation steps (e.g., removing/replacing failed disks).

Podcast also available on PocketCasts, SoundCloud, Spotify, Google Podcasts, Apple Podcasts, and RSS.

Leave a comment

The Podcast

Join Naomi Ellis as she dives into the extraordinary lives that shaped history. Her warmth and insight turn complex biographies into relatable stories that inspire and educate.

About the podcast