Hi All,
I'm looking to determine the storage usage for a particular data store in the below format (see the attachment)
Data store Name | Total Capacity | Used Space | Used % | Available Space | Remaining % | Total VM's | VM Used Space | Orphan Disk Space | Snapshot Space | Template Space |
is it possible to pull the above information from power cli script ?
Thanks
V
You mean this latest version?
$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
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.
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
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
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
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
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
There is an asterisk at the end of those strings.
Uncomment the one you want.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
You need to replace this line
with this line
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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.
You mean this latest version?
$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
Yes Sir. Thank you Again.