From 93b503e90063403ce65991a0687105a7874199e0 Mon Sep 17 00:00:00 2001 From: vr4manta Date: Fri, 15 Aug 2025 12:15:58 -0400 Subject: [PATCH] Added logic to clean up potential leftover spbm entity configs --- upi/vsphere/powercli/upi-destroy.ps1 | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/upi/vsphere/powercli/upi-destroy.ps1 b/upi/vsphere/powercli/upi-destroy.ps1 index 1fd94a181e..92e640ffa9 100644 --- a/upi/vsphere/powercli/upi-destroy.ps1 +++ b/upi/vsphere/powercli/upi-destroy.ps1 @@ -65,6 +65,9 @@ foreach ($vc in $vcenters) { Remove-Folder -Server $vcenter -Folder $($folder.Entity) -DeletePermanently -confirm:$false } + # Clean up CNS volumes + # TODO: Add cleanup for CNS here. This will be done in later PR. + # Clean up storage policy. Must be done after all other object cleanup except tag/tagCategory $storagePolicies = Get-SpbmStoragePolicy -Server $vcenter -Tag $tag @@ -80,8 +83,16 @@ foreach ($vc in $vcenters) { $clusterInventory = @(Get-Inventory -Server $vcenter -Name "$($clusterId)*" -ErrorAction Continue) if ($clusterInventory.Count -eq 0) { + # Remove policy from all configurations that still may exist + $entityConfig = Get-SpbmEntityConfiguration -StoragePolicy $policy + if ($null -ne $entityConfig -and $entityConfig -ne $null) { + Write-Host "Unsetting storage policy for "$entityConfig + Set-SpbmEntityConfiguration $entityConfig -StoragePolicy $null + } + + # Now we can delete the policy Write-Host "Removing policy: $($policy.Name)" - $policy | Remove-SpbmStoragePolicy -Server $vcenter -Confirm:$false + $policy | Remove-SpbmStoragePolicy -Server $vcenter -Confirm:$false -ErrorAction Continue } else { Write-Host "not deleting: $($clusterInventory)"