VMware Cloud Community
justinsmith
Enthusiast
Enthusiast
Jump to solution

One Liner to pull Storage Usage

I have a quick one liner that pulls the space used on each DS and the # of VM's. Im looking to add the cluter to this but cant seem to figure it out.... Id like it to run against vsphere and pull the cluster and add the cluster name to the spreadsheet as well.

#Run Connect-VIServer "vcenterservername" from powercli before running this script.... no need to add it to this script.
$vcenter = $defaultVIServers
Get-Datastore | Select Name,@{N="TotalSpaceGB";E={[Math]::Round(($_.ExtensionData.Summary.Capacity)/1GB,0)}},@{N="UsedSpaceGB";E={[Math]::Round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace)/1GB,0)}}, @{N="ProvisionedSpaceGB";E={[Math]::Round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB,0)}},@{N="NumVM";E={@($_ | Get-VM | where {$_.PowerState -eq "PoweredOn"}).Count}} | Sort Name | Export-Csv -Path H:\Excel_Reports\DS_Report.$vcenter.csv -NoTypeInformation -UseCulture

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

A quick-and-dirty way of doing this

Get-Datastore |

Select Name,

    @{N="Cluster";E={Get-VMHost -Datastore $_ | Select -First 1 | Get-Cluster | Select -ExpandProperty Name}},

    @{N="TotalSpaceGB";E={[Math]::Round(($_.ExtensionData.Summary.Capacity)/1GB,0)}},

    @{N="UsedSpaceGB";E={[Math]::Round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace)/1GB,0)}},

    @{N="ProvisionedSpaceGB";E={[Math]::Round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB,0)}},

    @{N="NumVM";E={@($_ | Get-VM | where {$_.PowerState -eq "PoweredOn"}).Count}} |

Sort Name |

Export-Csv -Path H:\Excel_Reports\DS_Report.$vcenter.csv -NoTypeInformation -UseCulture


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

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

A quick-and-dirty way of doing this

Get-Datastore |

Select Name,

    @{N="Cluster";E={Get-VMHost -Datastore $_ | Select -First 1 | Get-Cluster | Select -ExpandProperty Name}},

    @{N="TotalSpaceGB";E={[Math]::Round(($_.ExtensionData.Summary.Capacity)/1GB,0)}},

    @{N="UsedSpaceGB";E={[Math]::Round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace)/1GB,0)}},

    @{N="ProvisionedSpaceGB";E={[Math]::Round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB,0)}},

    @{N="NumVM";E={@($_ | Get-VM | where {$_.PowerState -eq "PoweredOn"}).Count}} |

Sort Name |

Export-Csv -Path H:\Excel_Reports\DS_Report.$vcenter.csv -NoTypeInformation -UseCulture


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

0 Kudos
kunaludapi
Expert
Expert
Jump to solution

@ Justin - I guess you are looking for datastore cluster

Get-Datastore |

    Select Name,

    @{N="TotalSpaceGB";E={[Math]::Round(($_.ExtensionData.Summary.Capacity)/1GB,0)}},

    @{N="UsedSpaceGB";E={[Math]::Round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace)/1GB,0)}},

    @{N="ProvisionedSpaceGB";E={[Math]::Round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB,0)}},

    @{N="NumVM";E={@($_ | Get-VM | where {$_.PowerState -eq "PoweredOn"}).Count}},

    @{N="DatastoreCluster";E={$_ | Get-DatastoreCluster}} |

    Sort Name | Export-Csv -Path H:\Excel_Reports\DS_Report.$vcenter.csv -NoTypeInformation -UseCulture

--------------------------------------------------------------- Kunal Udapi Sr. System Architect (Virtualization, Networking And Storage) http://vcloud-lab.com http://kunaludapi.blogspot.com VMWare vExpert 2014, 2015, 2016 If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
0 Kudos
justinsmith
Enthusiast
Enthusiast
Jump to solution

@LucD - That worked wonders. I had to remove the dev* but Im assuming you left it in when you were testing it Smiley Happy

Once again, thanks for the help.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Oops, indeed a relic from my test environment :smileyblush:


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

0 Kudos