vSAN Storage Policy Advanced Rules Report

Some time ago, I needed to audit all vSAN storage policies over multiple vCenter environments and confirm all the advanced policy rules were all set correctly. The process meant going through dozens of storage policies via the vSphere Web Client and documenting all the rules in a spreadsheet. This task was going to be tedious, so I wrote a simple script to extract all vSAN policies with their advanced rules and generate a report, the report can then be easily exported to a CSV if you wish.


Example Report captured from Powershell console


You can download the script from my GitHub Repo here vsan-spbm-rule-report.ps1 or hit the copy button below.


# This script extracts the Rules from vSAN Storage Policies and formats into a report.
# Tested on vSphere 6.7 Update 3.
# Script Author: Nicholas Mangraviti #VirtuallyWired
# Date: 20th October 2019
# Version: 1.0
# Blog URL: virtuallywired.io
# Usage: Just enter the vCenter URL or IP and Specify the Names of Policies to Exclude from the Report.


# You can add multiple vCenter Servers. Note Credentials need to work on all vCenters.

$vCenter = ("vc.virtuallywired.io") 

# Prompt for vCenter Credentials

$Creds = Get-Credential # Or Import Stored Credentials

# If you want to Exclude specific vSAN Policies from the Report, Add the name of the policy to this Array.

[array]$SpbmExclude = ("vSAN Default Storage Policy")

## Don't Edit Below This Line ##

Connect-VIServer -Server $vCenter -Credential $Creds

$VsanPolicies = Get-SpbmStoragePolicy | Where-Object { $_.AnyOfRuleSets -like "*VSAN*" -and $_.Name -notin $SpbmExclude }
$RuleSetReport = @()
Foreach ($VsanPolicy in $VsanPolicies) {

    $RuleSet = $VsanPolicy.AnyOfRuleSets.allOfRules

    $hostFailuresToTolerate = $RuleSet.Where( { $_.Capability.Name -eq "VSAN.hostFailuresToTolerate" }).Value
    $subFailuresToTolerate = $RuleSet.Where( { $_.Capability.Name -eq "VSAN.subFailuresToTolerate" }).Value
    $locality = $RuleSet.Where( { $_.Capability.Name -eq "VSAN.locality" }).Value
    $checksumDisabled = $RuleSet.Where( { $_.Capability.Name -eq "VSAN.checksumDisabled" }).Value
    $stripeWidth = $RuleSet.Where( { $_.Capability.Name -eq "VSAN.stripeWidth" }).Value
    $forceProvisioning = $RuleSet.Where( { $_.Capability.Name -eq "VSAN.forceProvisioning" }).Value
    $iopsLimit = $RuleSet.Where( { $_.Capability.Name -eq "VSAN.iopsLimit" }).Value
    $cacheReservation = $RuleSet.Where( { $_.Capability.Name -eq "VSAN.cacheReservation" }).Value
    $proportionalCapacity = $RuleSet.Where( { $_.Capability.Name -eq "VSAN.proportionalCapacity" }).Value
    $replicaPreference = $RuleSet.Where( { $_.Capability.Name -eq "VSAN.replicaPreference" }).Value

    $RuleSetReport += New-Object PSObject -Property ([ordered]@{
                
            StoragePolicyName      = $VsanPolicy.Name
            hostFailuresToTolerate = IF ($hostFailuresToTolerate -ne $null) { $hostFailuresToTolerate } else { "--" }
            subFailuresToTolerate  = IF ($subFailuresToTolerate -ne $null) { $subFailuresToTolerate } else { "--" }
            locality               = IF ($locality -ne $null) { $locality } else { "--" }            
            checksumDisabled       = IF ($checksumDisabled -ne $null) { $checksumDisabled } else { "--" }    
            stripeWidth            = IF ($stripeWidth -ne $null) { $stripeWidth } else { "--" }          
            forceProvisioning      = IF ($forceProvisioning -ne $null) { $forceProvisioning } else { "--" }    
            iopsLimit              = IF ($iopsLimit -ne $null) { $iopsLimit } else { "--" }           
            cacheReservation       = IF ($cacheReservation -ne $null) { $cacheReservation } else { "--" }     
            proportionalCapacity   = IF ($proportionalCapacity -ne $null) { $proportionalCapacity } else { "--" }  
            replicaPreference      = IF ($replicaPreference -ne $null) { $replicaPreference } else { "RAID-0 (No Data Redundancy)" }
            vCenter                = ([regex]::Matches($VsanPolicy.Uid, '@(.+):').Groups[1].Value)     

        })
}

Disconnect-VIServer * -Force -Confirm:$false -ErrorAction SilentlyContinue | Out-Null

$RuleSetReport | Format-Table -Property *

I hope you found this useful, if you have any feedback or need help adapting it to your environment, feel free to contact me. 🙂

Leave a Reply