Skip to content

Commit 93b503e

Browse files
committed
Added logic to clean up potential leftover spbm entity configs
1 parent 37a676e commit 93b503e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

upi/vsphere/powercli/upi-destroy.ps1

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ foreach ($vc in $vcenters) {
6565
Remove-Folder -Server $vcenter -Folder $($folder.Entity) -DeletePermanently -confirm:$false
6666
}
6767

68+
# Clean up CNS volumes
69+
# TODO: Add cleanup for CNS here. This will be done in later PR.
70+
6871
# Clean up storage policy. Must be done after all other object cleanup except tag/tagCategory
6972
$storagePolicies = Get-SpbmStoragePolicy -Server $vcenter -Tag $tag
7073

@@ -80,8 +83,16 @@ foreach ($vc in $vcenters) {
8083
$clusterInventory = @(Get-Inventory -Server $vcenter -Name "$($clusterId)*" -ErrorAction Continue)
8184

8285
if ($clusterInventory.Count -eq 0) {
86+
# Remove policy from all configurations that still may exist
87+
$entityConfig = Get-SpbmEntityConfiguration -StoragePolicy $policy
88+
if ($null -ne $entityConfig -and $entityConfig -ne $null) {
89+
Write-Host "Unsetting storage policy for "$entityConfig
90+
Set-SpbmEntityConfiguration $entityConfig -StoragePolicy $null
91+
}
92+
93+
# Now we can delete the policy
8394
Write-Host "Removing policy: $($policy.Name)"
84-
$policy | Remove-SpbmStoragePolicy -Server $vcenter -Confirm:$false
95+
$policy | Remove-SpbmStoragePolicy -Server $vcenter -Confirm:$false -ErrorAction Continue
8596
}
8697
else {
8798
Write-Host "not deleting: $($clusterInventory)"

0 commit comments

Comments
 (0)