VMware Cloud Community
AntonVZhbankov
Immortal
Immortal
Jump to solution

Clear VSAN partitions with PowerCLI

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?

EMCCAe, HPE ASE, MCITP: SA+VA, VCP 3/4/5, VMware vExpert XO (14 stars)
VMUG Russia Leader
http://t.me/beerpanda
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

5 Replies
LucD
Leadership
Leadership
Jump to solution

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

AntonVZhbankov
Immortal
Immortal
Jump to solution

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 ' '
}
EMCCAe, HPE ASE, MCITP: SA+VA, VCP 3/4/5, VMware vExpert XO (14 stars)
VMUG Russia Leader
http://t.me/beerpanda
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

AntonVZhbankov
Immortal
Immortal
Jump to solution

Well, it worked with .Invoke()

 

EMCCAe, HPE ASE, MCITP: SA+VA, VCP 3/4/5, VMware vExpert XO (14 stars)
VMUG Russia Leader
http://t.me/beerpanda
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Strange, that seems to work indeed.
One learns something new every day 😉


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos