Skip to content

Instantly share code, notes, and snippets.

@gowatana
Created February 11, 2018 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gowatana/891e4467e4a16b368c11ccb7b12a5966 to your computer and use it in GitHub Desktop.
Save gowatana/891e4467e4a16b368c11ccb7b12a5966 to your computer and use it in GitHub Desktop.
# vSAN Default Storage Policy Report Script.
#
# Created by: Go Watanabe / @gowatana
# Usage:
# PowerCLI> .\get_vsan_default_storage_policy.ps1 <vSAN Cluster Name>
# PowerCLI> .\get_vsan_default_storage_policy.ps1 vsan-cluster-03
# PowerCLI> .\get_vsan_default_storage_policy.ps1 vsan-cluster-03 |
# >> Out-File -Encoding utf8 -PSPath vsan-report.txt
$report_width = 100
$vsan_cluster_name = $args[0]
$test_vm_name = ("vsan-policy-check-vm-" + $vsan_cluster_name)
function report_table ($report_title, $report) {
"-" * $report_width
"# $report_title"
""
$report = $report | ft -AutoSize | Out-String
$report.Trim()
""
}
$vsan_cluster = Get-Cluster -Name $vsan_cluster_name | where {$_.VsanEnabled -eq $true}
if($vsan_cluster.Count -ne 1){
$vsan_cluster_name + " is not a vSAN Cluster."
exit
}
$vsan_cluster_info = $vsan_cluster | Get-VsanClusterConfiguration | select `
Cluster,
@{N="vSAN";E={$_.VsanEnabled}},
VsanDiskClaimMode,
@{N="SpaceEfficiency";E={$_.SpaceEfficiencyEnabled}},
@{N="StretchedCluster";E={$_.StretchedClusterEnabled}},
WitnessHost
$vsan_datastore = $vsan_cluster | Get-VMHost | select -First 1 | Get-Datastore | where {$_.Type -eq "vsan"}
$vsan_datastore_info = $vsan_datastore | select `
Name,
Type,
Datacenter,
ParentFolder
# Create check VM.
$vm = $vsan_cluster | Get-VMHost | Get-Random |
New-VM -StorageFormat Thin -DiskMB 10 -Name $test_vm_name -Datastore $vsan_datastore
# Get Default Storage Policy info.
$vsan_default_st_policy = ($vm | Get-SpbmEntityConfiguration).StoragePolicy
$vsan_default_st_policy_info = $vsan_default_st_policy |
select -ExpandProperty AnyOfRuleSets | % {
$RuleName = $_.Name
$_ | select -ExpandProperty AllOfRules | select `
Capability,
Value,
@{N="RuleName"; E={$RuleName}}
}
# Delete check VM.
$vm | Remove-VM -DeletePermanently -Confirm:$false
# Output report.
report_table "vSAN Cluster" $vsan_cluster_info
report_table "vSAN Datastore" $vsan_datastore_info
report_table "vSAN Dafault Storage Policy Name" $vsan_default_st_policy.Name
report_table "vSAN Dafault Storage Policy Capability Rules" $vsan_default_st_policy_info
@gowatana
Copy link
Author

gowatana commented Feb 11, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment