VMware Cloud Community
vmk2014
Expert
Expert
Jump to solution

Storage usage for a particular data store

Hi All,

I'm looking to determine the storage usage for a particular data store in the below format (see the attachment)

Data store NameTotal CapacityUsed SpaceUsed %Available SpaceRemaining %Total VM'sVM Used SpaceOrphan Disk SpaceSnapshot SpaceTemplate Space

is it possible to pull the above information from power cli script ?

Thanks

V

Tags (1)
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You mean this latest version?

$dsName = 'Windows_PowerMax_*'

$report = Get-Datastore -Name $dsName |

Select Name,

    @{N='CapacityGB';E={[math]::Round($_.CapacityGB)}},

    @{N='UsedGB';E={[math]::Round($_.CapacityGB - $_.FreeSpaceGB)}},

    @{N='UsedGB%';E={[math]::Round(($_.CapacityGB - $_.FreeSpaceGB)/$_.CapacityGB*100)}},

    @{N='FreeSpaceGB';E={[math]::Round($_.FreeSpaceGB)}},

    @{N='FreeSpaceGB%';E={[math]::Round($_.FreeSpaceGB/$_.CapacityGB*100)}},

    @{N='TotalVM';E={$_.ExtensionData.Vm.Count}},

    @{N='VMUsedGB';E={[math]::Round((Get-VM -Datastore $_ | Measure-Object -Property UsedSpaceGB -Sum).Sum)}},

    @{N='SnapshotGB';E={[math]::Round((Get-vm -Datastore $_ | Get-Snapshot | Measure-Object -Property SizeGB -Sum).Sum)}}


$report += '' | Select @{N='Name';E={'Total'}},

    @{N='CapacityGB';E={($report | Measure-Object -Property CapacityGB -Sum).Sum}},

    @{N='UsedGB';E={($report | Measure-Object -Property UsedGB -Sum).Sum}},

    @{N='UsedGB%';E={}},

    @{N='FreeSpaceGB';E={($report | Measure-Object -Property FreeSpaceGB -Sum).Sum}},

    @{N='FreeSpaceGB%';E={($report | Measure-Object -Property 'FreeSpaceGB%' -Average).Average}},

    @{N='TotalVM';E={}},

    @{N='VMUsedGB';E={}},

    @{N='SnapshotGB';E={}}


$report | Export-Csv -Path D:\temp\StorageUsage2.csv -NoTypeInformation -UseCulture


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

View solution in original post

10 Replies
LucD
Leadership
Leadership
Jump to solution

The following will give you all fields, except for the orphaned data.

The reason is that determining what is orphaned data or not is hard to automate.

That' s also the reason why my script to discover orphaned files and folders doesn't do deletes automatically.

Get-Datastore |

Select Name,CapacityGB,

    @{N='UsedGB';E={[math]::Round($_.CapacityGB - $_.FreeSpaceGB)}},

    @{N='UsedGB%';E={[math]::Round(($_.CapacityGB - $_.FreeSpaceGB)/$_.CapacityGB*100)}},

    @{N='FreeSpaceGB';E={[math]::Round($_.FreeSpaceGB)}},

    @{N='FreeSpaceGB%';E={[math]::Round($_.FreeSpaceGB/$_.CapacityGB*100)}},

    @{N='TotalVM';E={$_.ExtensionData.Vm.Count}},

    @{N='VMUsedGB';E={[math]::Round((Get-VM -Datastore $_ | Measure-Object -Property UsedSpaceGB -Sum).Sum)}},

    @{N='SnapshotGB';E={[math]::Round((Get-vm -Datastore $_ | Get-Snapshot | Measure-Object -Property SizeGB -Sum).Sum)}}


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

0 Kudos
vmk2014
Expert
Expert
Jump to solution

Hi LucD,

There are 2 things, i'm looking to add here. Can we get the for data store usage for a specific data store name WIndows_PowerMax_0000 or for all Powermax data store usage

WindowsVMax_0000  or  for all Vmax data store usage ? Also total size at the end of report like  Total used space is 79 TB and free space available Total is 60 TB in every column.

Thanks

V

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You could do something like this.

By changing the content of $dsName you can get the report for 1 datastore, a selection of datastores or all datastores

#$dsName = 'WIndows_PowerMax_0000'

#$dsName = '*PowerMax*'

$dsName = '*'

$report = Get-Datastore -Name $dsName |

Select Name,

    @{N='CapacityGB';E={[math]::Round($_.CapacityGB)}},

    @{N='UsedGB';E={[math]::Round($_.CapacityGB - $_.FreeSpaceGB)}},

    @{N='UsedGB%';E={[math]::Round(($_.CapacityGB - $_.FreeSpaceGB)/$_.CapacityGB*100)}},

    @{N='FreeSpaceGB';E={[math]::Round($_.FreeSpaceGB)}},

    @{N='FreeSpaceGB%';E={[math]::Round($_.FreeSpaceGB/$_.CapacityGB*100)}},

    @{N='TotalVM';E={$_.ExtensionData.Vm.Count}},

    @{N='VMUsedGB';E={[math]::Round((Get-VM -Datastore $_ | Measure-Object -Property UsedSpaceGB -Sum).Sum)}},

    @{N='SnapshotGB';E={[math]::Round((Get-vm -Datastore $_ | Get-Snapshot | Measure-Object -Property SizeGB -Sum).Sum)}}


$report += '' | Select @{N='Name';E={'Total'}},

    @{N='CapacityGB';E={($report | Measure-Object -Property CapacityGB -Sum).Sum}},

    @{N='UsedGB';E={}},

    @{N='UsedGB%';E={}},

    @{N='FreeSpaceGB';E={($report | Measure-Object -Property FreeSpaceGB -Sum).Sum}},

    @{N='FreeSpaceGB%';E={}},

    @{N='TotalVM';E={}},

    @{N='VMUsedGB';E={}},

    @{N='SnapshotGB';E={}}

$report


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

0 Kudos
vmk2014
Expert
Expert
Jump to solution

Sorry, it still gives the same output as earlier script.

#$dsName = 'WIndows_PowerMax_*'

#$dsName = '*PowerMax*'

Data store name starts like Windows_powermax3441/powermax4432 etc, hence i used astrix at the end.

Also, total value for Total % free not showing.

Thanks

V

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You didn't ask for Total % Free.
That would be an average, not a total (which doesn't make sense for percentages).

Change the line in the Totals select to

    @{N='FreeSpaceGB%';E={($report | Measure-Object -Property 'FreeSpaceGB%' -Average).Average}},

There is an asterisk at the end of those strings.

Uncomment the one you want.


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

0 Kudos
vmk2014
Expert
Expert
Jump to solution

just to confirm $report += '' | Select @{N='Name';E={'Total'}},

need to replace by  @{N='FreeSpaceGB%';E={($report | Measure-Object -Property 'FreeSpaceGB%' -Average).Average}},

but it will give only value for  % average percentage free. I'm looking for  total for Used space/Avaiable space and % Remaining (Average as you said)

thanks

V

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You need to replace this line

@{N='FreeSpaceGB%';E={}},

with this line

@{N='FreeSpaceGB%';E={($report | Measure-Object -Property 'FreeSpaceGB%' -Average).Average}},


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

0 Kudos
vmk2014
Expert
Expert
Jump to solution

My apology, i deleted the thread by mistake. Can you please paste it again. I did mark  as correct but while editing sentence it got deleted.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You mean this latest version?

$dsName = 'Windows_PowerMax_*'

$report = Get-Datastore -Name $dsName |

Select Name,

    @{N='CapacityGB';E={[math]::Round($_.CapacityGB)}},

    @{N='UsedGB';E={[math]::Round($_.CapacityGB - $_.FreeSpaceGB)}},

    @{N='UsedGB%';E={[math]::Round(($_.CapacityGB - $_.FreeSpaceGB)/$_.CapacityGB*100)}},

    @{N='FreeSpaceGB';E={[math]::Round($_.FreeSpaceGB)}},

    @{N='FreeSpaceGB%';E={[math]::Round($_.FreeSpaceGB/$_.CapacityGB*100)}},

    @{N='TotalVM';E={$_.ExtensionData.Vm.Count}},

    @{N='VMUsedGB';E={[math]::Round((Get-VM -Datastore $_ | Measure-Object -Property UsedSpaceGB -Sum).Sum)}},

    @{N='SnapshotGB';E={[math]::Round((Get-vm -Datastore $_ | Get-Snapshot | Measure-Object -Property SizeGB -Sum).Sum)}}


$report += '' | Select @{N='Name';E={'Total'}},

    @{N='CapacityGB';E={($report | Measure-Object -Property CapacityGB -Sum).Sum}},

    @{N='UsedGB';E={($report | Measure-Object -Property UsedGB -Sum).Sum}},

    @{N='UsedGB%';E={}},

    @{N='FreeSpaceGB';E={($report | Measure-Object -Property FreeSpaceGB -Sum).Sum}},

    @{N='FreeSpaceGB%';E={($report | Measure-Object -Property 'FreeSpaceGB%' -Average).Average}},

    @{N='TotalVM';E={}},

    @{N='VMUsedGB';E={}},

    @{N='SnapshotGB';E={}}


$report | Export-Csv -Path D:\temp\StorageUsage2.csv -NoTypeInformation -UseCulture


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

vmk2014
Expert
Expert
Jump to solution

Yes Sir. Thank you Again.

0 Kudos