VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Issue getting the Cluster details for Datastores

Hi,

I have a issue getting the cluster details for Datastores which are presented to multiple clusters.

Below scripts shows the cluster details of the datastores but if the datastore is part of multiple clusters, it shows only once in first cluster output and it is not showing in second cluster output.

Please help.

Script

Get-Cluster -PipelineVariable cluster |

Get-Datastore |

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

Datacenter, Name,

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

@{N="Used (GB)";E={[math]::Round(($_.CapacityGB)-($_.FreeSpaceGB),0)}},

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

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

@{N="FreeSpace (%)";E={"{0:P}" -f (($_.FreeSpaceGB)/($_.CapacityGB))}},

@{N="VMFS_Ver";E={$_.FileSystemVersion}},

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

@{N="Vendor";E={(Get-EsxCli -VMHost (Get-VMHost -Datastore $_ | Select -First 1)).storage.core.device.list($_.ExtensionData.Info.Vmfs.Extent[0].DiskName).Vendor}},

@{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')}},

@{N='MultiPathPolicy';E={$esxcli = Get-EsxCli -VMHost (Get-VMHost -Datastore $_ | Select -First 1)

    $esxcli.storage.nmp.device.list($_.ExtensionData.Info.Vmfs.Extent[0].DiskName) | Select -ExpandProperty PathSelectionPolicy}}   

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try like this

Get-Cluster -PipelineVariable cluster |

    ForEach-Object -Process {

        Get-Datastore -RelatedObject $cluster |

            Select-Object @{N = 'Cluster'; E = { $cluster.Name } },

            Datacenter, Name,

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

            @{N = "Used (GB)"; E = { [math]::Round(($_.CapacityGB) - ($_.FreeSpaceGB), 0) } },

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

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

            @{N = "FreeSpace (%)"; E = { "{0:P}" -f (($_.FreeSpaceGB) / ($_.CapacityGB)) } },

            @{N = "VMFS_Ver"; E = { $_.FileSystemVersion } },

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

            @{N = "Vendor"; E = { (Get-EsxCli -VMHost (Get-VMHost -Datastore $_ | Select-Object -First 1)).storage.core.device.list($_.ExtensionData.Info.Vmfs.Extent[0].DiskName).Vendor } },

        @{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') }

        },

        @{N = 'MultiPathPolicy'; E = { $esxcli = Get-EsxCli -VMHost (Get-VMHost -Datastore $_ | Select-Object -First 1)

            $esxcli.storage.nmp.device.list($_.ExtensionData.Info.Vmfs.Extent[0].DiskName) | Select-Object -ExpandProperty PathSelectionPolicy }

}

}


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

Try like this

Get-Cluster -PipelineVariable cluster |

    ForEach-Object -Process {

        Get-Datastore -RelatedObject $cluster |

            Select-Object @{N = 'Cluster'; E = { $cluster.Name } },

            Datacenter, Name,

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

            @{N = "Used (GB)"; E = { [math]::Round(($_.CapacityGB) - ($_.FreeSpaceGB), 0) } },

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

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

            @{N = "FreeSpace (%)"; E = { "{0:P}" -f (($_.FreeSpaceGB) / ($_.CapacityGB)) } },

            @{N = "VMFS_Ver"; E = { $_.FileSystemVersion } },

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

            @{N = "Vendor"; E = { (Get-EsxCli -VMHost (Get-VMHost -Datastore $_ | Select-Object -First 1)).storage.core.device.list($_.ExtensionData.Info.Vmfs.Extent[0].DiskName).Vendor } },

        @{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') }

        },

        @{N = 'MultiPathPolicy'; E = { $esxcli = Get-EsxCli -VMHost (Get-VMHost -Datastore $_ | Select-Object -First 1)

            $esxcli.storage.nmp.device.list($_.ExtensionData.Info.Vmfs.Extent[0].DiskName) | Select-Object -ExpandProperty PathSelectionPolicy }

}

}


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD. That was quick and perfect Smiley Happy

0 Kudos