Skip to content

Instantly share code, notes, and snippets.

@lamw
Last active September 9, 2020 09:10
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lamw/2a10d4941baf140f94d15f68d951c4c9 to your computer and use it in GitHub Desktop.
Save lamw/2a10d4941baf140f94d15f68d951c4c9 to your computer and use it in GitHub Desktop.
List all Unassociated/Orphaned vSAN Objects using PowerCLI
$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
@ashishsharma-git
Copy link

ashishsharma-git commented Sep 9, 2020

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) {
$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)
}
}
}
##############################################################

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment