PowerCLI

 View Only
  • 1.  Get datastore with cluster name

    Posted Apr 03, 2025 02:36 PM

    Hello,

    I'm trying to get a list of all datastores in my environment with their naa numbers which is pretty easy with this command:

    Get-Datastore | select Name,State,@{N="naa";E={$_.ExtensionData.Info.Vmfs.Extent.DiskName}}

    I would also like to add the datastorecluster name when the datastore resides in a datastorecluster. The challenge is that some of these reside in clusters, others do no, but I want to make sure I list all the datastores in my environment. 

    Any suggestions?



  • 2.  RE: Get datastore with cluster name
    Best Answer

    Posted Apr 04, 2025 01:17 PM
    Edited by dbutch1976 Apr 08, 2025 11:02 AM

    $DataStoreViews = Get-View -ViewType Datastore -Server $vCenter -Property Name, Info | Sort Name
    $DataStoreClusterViews = Get-View -ViewType StoragePod -Server $vCenter -Property Name, ChildEntity
    ForEach($DataStoreView in $DataStoreViews){
        $DataStoreClusterView = $Null
        $DataStoreClusterView = $DataStoreClusterViews | Where{($_.ChildEntity -Contains $DataStoreView.MoRef) -AND ($_.Client.ServiceUrl.Split('/')[2] -eq $DataStoreView.Client.ServiceUrl.Split('/')[2])}
        $DataStoreView | Select Name, OverallStatus, @{N="CanonicalName";E={$_.Info.Vmfs.Extent.DiskName}}, @{N="DSCluster"; E={$DataStoreClusterView.Name}}
    }