Common task for R&D Lab. I have moderately large VSAN cluster with large number of disks previously participated in VSAN.
vCenter task "Erase all partitions" fails
The only way to clean is to ssh to all ESXi hosts and "esxcli vsan strorage remove"
Current status: I can get all GroupUUID by host and generate .sh files for each host with corresponding "esxcli vsan storage remove --uuid 521a2882-0d7f-ef06-a117-d436718c6248"
It makes life easier, but still a lot of manual work for 10+ hosts cluster.
Get-ESXCli provides vsan.storage abstraction with remove method, but with unclear documentation and no examples.
Please point me to right direction - how can I clear VSAN partitions 100% automated?
When you use the V2 switch, help is available
$esxcli = Get-EsxCli -VMHost <MyEsx> -V2
$esxcli.vsan.storage.remove.Help()
You can create the hash table, fill in the required parameter, and then Invoke the method.
$remVSAN = $esxcli.vsan.storage.remove.CreateArgs()
$remVSAN['uuid'] = <a groupUuid>
$esxcli.vsan.storage.remove.Invoke($remVSAN)
You can loop over all ESXi nodes and then all UUIDs
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
When you use the V2 switch, help is available
$esxcli = Get-EsxCli -VMHost <MyEsx> -V2
$esxcli.vsan.storage.remove.Help()
You can create the hash table, fill in the required parameter, and then Invoke the method.
$remVSAN = $esxcli.vsan.storage.remove.CreateArgs()
$remVSAN['uuid'] = <a groupUuid>
$esxcli.vsan.storage.remove.Invoke($remVSAN)
You can loop over all ESXi nodes and then all UUIDs
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Great help, may thanks.
Working code for reference:
foreach ($vmhost in $vmhosts) {
$esxcli = Get-EsxCli -VMHost $vmhost -V2
[String[]]$diskGroups = @()
$diskgroups += $esxcli.vsan.storage.list.Invoke() | findstr "pUUID"
[String[]]$uniqueDiskGroups = $diskGroups | Sort-Object -Unique
Write-Host 'Processing host' $vmhost.Name
Write-Host ' - Disk groups found '
$uniqueDiskGroups
Write-Host ' -'
foreach ($groupUUID in $uniqueDiskGroups) {
$UUID = $groupUUID.Substring(31, 36)
Write-Host 'Removing '$UUID
$remVSAN = $esxcli.vsan.storage.remove.CreateArgs.Invoke()
$remVSAN.uuid = $UUID;
$esxcli.vsan.storage.remove.Invoke($remVSAN)
}
Write-Host ' -'
Write-Host ' '
}
I think you have a typo in 1 line.
This
$remVSAN = $esxcli.vsan.storage.remove.CreateArgs.Invoke()
should be
$remVSAN = $esxcli.vsan.storage.remove.CreateArgs()
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Well, it worked with .Invoke()
Strange, that seems to work indeed.
One learns something new every day 😉
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference