PowerCLI

 View Only
  • 1.  Clear VSAN partitions with PowerCLI

    Posted May 13, 2023 06:31 PM

    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?



  • 2.  RE: Clear VSAN partitions with PowerCLI
    Best Answer

    Posted May 13, 2023 07:21 PM

    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



  • 3.  RE: Clear VSAN partitions with PowerCLI

    Posted May 14, 2023 01:34 AM

    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 ' '
    }


  • 4.  RE: Clear VSAN partitions with PowerCLI

    Posted May 14, 2023 05:02 AM

    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()


  • 5.  RE: Clear VSAN partitions with PowerCLI

    Posted May 14, 2023 05:03 AM

    Well, it worked with .Invoke()

     



  • 6.  RE: Clear VSAN partitions with PowerCLI

    Posted May 14, 2023 05:12 AM

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