vSAN Storage Policy Summary using PowerCLI

Posted by Stephan McTighe on 26 Feb 2023

I recently came across a need to review the Storage Policies in use within a vCenter environment and how many objects or virtual machines where using each policy.

I saw this as an excuse to refresh my PowerShell skills and wrote a quick function.

Source code can be found on my GitHub, here. Check there for any updates but below is the code at the time of writing.


 1function Get-vSANSPSummary {
 2    <#
 3    .SYNOPSIS
 4        Export vSAN Storage Policy Information.
 5    .DESCRIPTION
 6        Export vSAN Storage Policies from vCenter showing FTT & Stripe information and amount of amount of VM's using each.
 7    .PARAMETER ExportPath
 8        Path the export the output HTML file.
 9    .NOTES
10        Tags: VMware, vCenter, SPBM, PowerCLI, API
11        Author: Stephan McTighe
12        Website: stephanmctighe.com
13    .EXAMPLE
14        PS C:\> Get-vSANSPSummary -ExportPath "C:\report\vSAN-Storage-Policy-Summary.html"
15        Outputs a HTML file containing the Storage Policy Information for vSAN Storage Policies to a specified location.
16
17#>
18#Requires -Modules VMware.VimAutomation.Storage
19    [CmdletBinding()]
20    param (
21        [Parameter(Mandatory)]
22        [string] $ExportFilePath)
23
24    Begin {}
25
26    Process {
27        try {
28            $Output = @()
29            $vSANstoragepolicies = Get-SpbmStoragePolicy -Namespace "VSAN"
30            $SPBM = $vSANstoragepolicies | Select-Object Name, AnyOfRuleSets
31            ForEach ($SP in $SPBM) {
32                $Attributes = @( $SP | ForEach-Object { $_.AnyOfRuleSets } | Select-Object -ExpandProperty AllofRules)
33                $object = [PSCustomObject]@{
34                    SPName         = $SP.Name
35                    ObjectCount    = $ObjectCount = (Get-SpbmEntityConfiguration -StoragePolicy "$($SP.name)").count
36                    VMCount        = $VMCount = (Get-SpbmEntityConfiguration -StoragePolicy "$($SP.Name)" | Where-Object {$_.Entity -notlike "hard*"}).count
37                    RAID           = $attributes | Where-Object { $_.Capability -like "*VSAN.replicaPreference*" } | Select-Object -ExpandProperty Value
38                    FTT            = $attributes | Where-Object { $_.Capability -like "*VSAN.hostFailuresToTolerate*" } | Select-Object -ExpandProperty Value
39                    SubFTT         = $attributes | Where-Object { $_.Capability -like "*VSAN.subFailuresToTolerate*" } | Select-Object -ExpandProperty Value
40                    Stripes        = $attributes | Where-Object { $_.Capability -like "*VSAN.stripeWidth*" } | Select-Object -ExpandProperty Value
41                    ForceProvision = $attributes | Where-Object { $_.Capability -like "*VSAN.forceProvisioning*" } | Select-Object -ExpandProperty Value
42                    StorageType    = $attributes | Where-Object { $_.Capability -like "*VSAN.storageType*" } | Select-Object -ExpandProperty Value
43                    IOPSLimit      = $attributes | Where-Object { $_.Capability -like "*VSAN.iopsLimit*" } | Select-Object -ExpandProperty Value
44
45                }
46                $Output += $object
47
48            }
49            $Output | ConvertTo-Html -Property SPName, VMCount, ObjectCount, RAID, FTT, SubFTT, Stripes, ForceProvision, StorageType, IOPSLimit | Out-File $ExportFilePath
50        }
51        catch {
52            Write-Host "An error occurred!" -ForegroundColor Red
53            Write-Host $_ -ForegroundColor Red
54        }
55
56    }
57}

Output currently as a basic HTML table but you could change this to add some ‘HTMLness’ or output to CSV.

Sample Output

C:\Users\Peppa\OneDrive - stephanmctighe.com\Documents\GitHub_Repos\stephanmctighe.com\content\posts\vSAN Storage Policy Summary using PowerCLI\images\image1.jpg

As always, thanks for reading and I hope this has been useful to someone.

If you like my content, consider following me on Twitter so you don’t miss out!