Last active
September 9, 2020 09:10
-
-
Save lamw/2a10d4941baf140f94d15f68d951c4c9 to your computer and use it in GitHub Desktop.
List all Unassociated/Orphaned vSAN Objects using PowerCLI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ClusterName = "Cluster-01" | |
$clusterView = Get-Cluster $ClusterName | |
$vmhost = ($clusterView | Get-VMHost) | select -First 1 | |
$vsanClusterObjectSys = Get-VsanView -Id VsanObjectSystem-vsan-cluster-object-system | |
$results = (($vsanClusterObjectSys.VsanQueryObjectIdentities($clusterMoRef,$null,$null,$true,$true,$false)).Identities | where {$_.Vm -eq $null}) | |
foreach ($result in $results) { | |
$jsonResult = ($vsanIntSys.GetVsanObjExtAttrs($result.Uuid)) | ConvertFrom-JSON | |
foreach ($object in $jsonResult | Get-Member) { | |
# crappy way to iterate through keys ... | |
if($($object.Name) -ne "Equals" -and $($object.Name) -ne "GetHashCode" -and $($object.Name) -ne "GetType" -and $($object.Name) -ne "ToString") { | |
$objectID = $object.name | |
$jsonResult.$($objectID) | |
} | |
} | |
} | |
## Each Unassociated/Oprhan vSAN Object will have the followingn structure: | |
UUID : ca253f5c-a897-3421-73ec-246e96d1346a | |
Object type : vsan | |
Object size : 273804165120 | |
User friendly name : MGMT-VCG-02 | |
HA metadata : (null) | |
Allocation type : Thin | |
Policy : (("stripeWidth" i1) ("cacheReservation" i0) ("proportionalCapacity" (i0 i100)) ("hostFailuresToTolerate" i1) ("forceProvisioning" i0) | |
("spbmProfileId" "aa6d5a82-1c88-45da-85d3-3d74b91a5bad") ("spbmProfileGenerationNumber" l+0) ("objectVersion" i7) ("CSN" l72) ("SCSN" l76) | |
("spbmProfileName" "vSAN Default Storage Policy")) | |
Object class : vmnamespace | |
Object capabilities : NONE | |
Object path : /vmfs/volumes/vsan:522472d54b84dbad-15fdbdf65aa0fed0/MGMT-VCG-02 | |
Group uuid : 00000000-0000-0000-0000-000000000000 | |
Container uuid : 00000000-0000-0000-0000-000000000000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried the code and its not working. $ClusterMoRef and $vsanIntSys aren't defined but used within the script. The two need to be defined -
$ClusterMoRef = $Clusterview.ExtensionData.MoRef
$vsanIntSys = Get-View $vmhost.ExtensionData.configManager.vsanInternalSystem
Here's a working copy of the script
############################################################
$clustername = "Cluster-01"
$clusterView = Get-Cluster $ClusterName
$ClusterMoRef = $Clusterview.ExtensionData.MoRef
$vmhost = ($clusterView | Get-VMHost) | select -First 1
$vsanIntSys = Get-View $vmhost.ExtensionData.configManager.vsanInternalSystem
$vsanClusterObjectSys = Get-VsanView -Id VsanObjectSystem-vsan-cluster-object-system
$results = (($vsanClusterObjectSys.VsanQueryObjectIdentities($clusterMoRef,$null,$null,$true,$true,$false)).Identities | where {$_.Vm -eq $null})
foreach ($result in $results) {$object.Name) -ne "Equals" -and $ ($object.Name) -ne "GetHashCode" -and $ ($object.Name) -ne "GetType" -and $ ($object.Name) -ne "ToString") {
$jsonResult.$ ($objectID)
$jsonResult = ($vsanIntSys.GetVsanObjExtAttrs($result.Uuid)) | ConvertFrom-JSON
foreach ($object in $jsonResult | Get-Member) {
# crappy way to iterate through keys ...
if($(
$objectID = $object.name
}
}
}
##############################################################