VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot

List All Datastores based on vCenter Cluster

Hi,

I am issues listing datastores based on vCenter cluster. below script just shows same cluster name for all datastores.

Get-Datastore | Select Name, Datacenter,

@{N="Cluster"; E={(Get-Cluster).Name}},

@{N="CapacityInGB"; E={[math]::round($_.CapacityGB)}},

@{N="Provisioned (GB)"; E={[math]::round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB,2) }},

@{N="FreeSpaceInGB";E={[math]::round($_.FreeSpaceGB)}},

@{N="VM Count";E={$_.ExtensionData.VM.Count}},

@{N="CanonicalName";E={$_.ExtensionData.Info.Vmfs.Extent[0].DiskName}},

@{N="LUN";E={

             $esx = Get-View -Id $_.ExtensionData.Host[0].Key -Property Name

             $dev = $_.ExtensionData.Info.Vmfs.Extent[0].DiskName

             $esxcli = Get-EsxCli -VMHost $esx.Name -V2

             $esxcli.storage.nmp.path.list.Invoke(@{'device'=$dev}).RuntimeName.Split(':')[-1].TrimStart('L')}}

0 Kudos
6 Replies
LucD
Leadership
Leadership

Change that line into

@{N="Cluster"; E={(Get-VMHost -Datastore $_ | Get-Cluster).Name}},


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot

Hi LucD,

After replacing the below line, Script is taking much longer than before.

Also, Few of the Datastores which are common between two clusters are showing in one cluster but not showing in other cluster

0 Kudos
LucD
Leadership
Leadership

If a datastore is visible in multiple clusters, what do you want displayed?

All the clusternames?

Yes, the script could become a bit slower.

We could tackle that by switching to Get-View and vSphere objects, but lets first get the logic right.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot

Hi LucD,

When we have shared Datastores across multiple clusters, I would like to see the name of the cluster name independently

Example :

Datastore1     Cluster1

Datastore1     Cluster2

Here Datastore1 is visible in both Clusters and I would like to get similar list and highlight repeated datastore.

0 Kudos
kwhornlcs
Enthusiast
Enthusiast

This will likely have the logic you're looking for:

$output = @()

Get-Cluster| %{

    $cluster = $_

    $output += $cluster|Get-Datastore | Select Name, Datacenter,@{N="Cluster"; E={$cluster.name}},

    @{N="CapacityInGB"; E={[math]::round($_.CapacityGB)}},

    @{N="Provisioned (GB)"; E={[math]::round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB,2)}},

    @{N="FreeSpaceInGB";E={[math]::round($_.FreeSpaceGB)}},

    @{N="VM Count";E={$_.ExtensionData.VM.Count}},

    @{N="CanonicalName";E={$_.ExtensionData.Info.Vmfs.Extent[0].DiskName}},

    @{N="LUN";E={

             $esx = Get-View -Id $_.ExtensionData.Host[0].Key -Property Name

             $dev = $_.ExtensionData.Info.Vmfs.Extent[0].DiskName

             $esxcli = Get-EsxCli -VMHost $esx.Name -V2

             $esxcli.storage.nmp.path.list.Invoke(@{'device'=$dev}).RuntimeName.Split(':')[-1].TrimStart('L')}}

    }

$output|Sort Name|FT -Autosize

0 Kudos
LucD
Leadership
Leadership

Try like this

Get-Cluster -PipelineVariable cluster | Get-Datastore

Select Name, Datacenter,

@{N="Cluster"; E={$cluster.Name}},

@{N="CapacityInGB"; E={[math]::round($_.CapacityGB)}},

@{N="Provisioned (GB)"; E={[math]::round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB,2) }},

@{N="FreeSpaceInGB";E={[math]::round($_.FreeSpaceGB)}},

@{N="VM Count";E={$_.ExtensionData.VM.Count}},

@{N="CanonicalName";E={$_.ExtensionData.Info.Vmfs.Extent[0].DiskName}},

@{N="LUN";E={

             $esx = Get-View -Id $_.ExtensionData.Host[0].Key -Property Name

             $dev = $_.ExtensionData.Info.Vmfs.Extent[0].DiskName

             $esxcli = Get-EsxCli -VMHost $esx.Name -V2

             $esxcli.storage.nmp.path.list.Invoke(@{'device'=$dev}).RuntimeName.Split(':')[-1].TrimStart('L')}}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos