VMware Cloud Community
PorzioM
Contributor
Contributor
Jump to solution

Finding Provisioned Space on a datastore

I am trying to list out the items from the Capacity pane on the summay tab of Datastores:

What I have so far is:

Get-Datastore | Select-Object -Property Name, Datacenter, CapacityGB, FreeSpaceGB | Export-Csv c:\info.csv -NoTypeInformation


I do not see a property for Provisioned Space, I only see the following proerties. How do I change this script to get the information I need. Thanks for the help.

FileSystemVersion            

DatacenterId                 

Datacenter                   

ParentFolderId               

ParentFolder                 

DatastoreBrowserPath        

FreeSpaceMB                 

CapacityMB                   

Accessible                   

Type                          

StorageIOControlEnabled      

CongestionThresholdMillisecond

Name                         

ExtensionData                

CapacityGB                   

FreeSpaceGB                   

Id                            

Uid

Mike P

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

So you are in fact not looking for historical data.

Then you can do it even simpler

Get-Datastore | Select Name, Datacenter,CapacityGB,FreeSpaceGB, 
@{N="Provisioned (GB)"; E={[math]::round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB,2) }}| 
Sort-Object -Property Name |
Export-Csv c:\test.csv -NoTypeInformation


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

View solution in original post

0 Kudos
23 Replies
nielse
Expert
Expert
Jump to solution

Hello Mike,

Luc Dekens wrote a script and blogpost about this. I think your answer can be found within his script, you can find it at http://www.lucd.info/2011/06/19/datastore-usage-statistics/.

It shows used space, capacity and allocated (provisioned).

@nielsengelen - http://foonet.be - VCP4/5
0 Kudos
PorzioM
Contributor
Contributor
Jump to solution

Thanks, looks good but on one of my vCenter servers It gives me an error:

Export-Csv : Cannot bind argument to parameter 'InputObject' because it is null.
At line:16 char:21
+ $report | Export-Csv <<<<  "C:\DS-stats.csv" -NoTypeInformation -UseCulture
    + CategoryInfo          : InvalidData: (:) [Export-Csv], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ExportCsvCommand

I get that error when I run the Script LucD wrote

$metrics = "disk.capacity.latest","disk.provisioned.latest",
            "disk.used.latest"
$report = Get-Stat2 -entity $ds -stat $metrics -interval "HI2" | `
Sort-Object -Property Timestamp | `
Group-Object -Property Timestamp | %{
  New-Object PSObject -Property @{
    Timestamp = $_.Name
    "Capacity (GB)" = [Math]::Round(($_.Group | `
     where {$_.CounterName -eq "disk.capacity.latest"}).Value/1MB,2)
    "Allocated (GB)" = [Math]::Round(($_.Group | `
     where {$_.CounterName -eq "disk.provisioned.latest"}).Value/1MB,2)
    "Used (GB)" = [Math]::Round(($_.Group | `
     where {$_.CounterName -eq "disk.used.latest"}).Value/1MB,2)
  }
}
$report | Export-Csv "C:\DS-stats.csv" -NoTypeInformation -UseCulture

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Most of the time that is an indication that $report is empty.

What time interval did you request ?

Are the performance data available in the vCenter DB ? In other words can you see data in the graph when you use the Performance tab in the vSphere client ?


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

0 Kudos
PorzioM
Contributor
Contributor
Jump to solution

Not sure what Time interval I requested. I just used your example.

I just realized I may not be getting the exact data I need with this one though.

Is ther ea way to alter this script to give me an output like this:

Datastore Name     |     Capacity GB    |    Provisioned Space GB    |    Free Space GB

Thanks again Luc

MikeP

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The example on my blog used Historical Interval 2 (HI2) or data from the past week.

Can you check in the vSphere client if there is data available for that timerange ?

I replied on your question on my blog, let me know if that adapted script is what you are looking for ?


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

0 Kudos
PorzioM
Contributor
Contributor
Jump to solution

some of the datastores are (inactive) so maybe that is what is causing it

I tried running the script sample you posted for me on your blog and recieved an error. I ran it form the vCenter that was sucessfull last time.

-Entity parameters should be of type HostSystem, VirtualMachine, ClusterComputeResource, Datastore or ResourcePool
At line:53 char:10
+     Throw <<<<  "-Entity parameters should be of type HostSystem, VirtualMachine, ClusterComputeResource, Datastore or ResourcePool"
    + CategoryInfo          : OperationStopped: (-Entity paramet...or ResourcePool:String) [], RuntimeException
    + FullyQualifiedErrorId : -Entity parameters should be of type HostSystem, VirtualMachine, ClusterComputeResource, Datastore or ResourcePool

I am really looking for an output similar to this:

I've got one that does everything except the Provisioned Space piece. It's just really important to have the Porvisioned storage piece in this report. I have been adding that column manually and that takes quite a while with the number of datastores across all of our vCenters.

Thanks again Luc.

NameDatacenterCapacityGBFreeSpaceGBProvisioned
AMP-Datastore-00My Datacenter787.7919922549.27929691024.09
Clone_Copy_LUN_6000My Datacenter499.75499.16406250.5859375
Clone_Copy_LUN_6001My Datacenter499.75499.16406250.5859375
Clone_Copy_LUN_6002My Datacenter499.75499.16406250.5859375

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Oops, there was a typo in that script I posted.

It's corrected now, can you try again ?


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

0 Kudos
PorzioM
Contributor
Contributor
Jump to solution

it seems to give me output for only one of my 160 LUNs with different time stamps.

There were 334 lines like this in the csv

TimestampUsed (GB)Datastore NameCapacity (GB)Allocated (GB)
6/7/2012 22:00914.4VeeamBackup_DCNA-P-VRM-011740.8914.4
6/7/2012 22:30914.4VeeamBackup_DCNA-P-VRM-011740.8914.4
6/7/2012 23:00914.4VeeamBackup_DCNA-P-VRM-011740.8914.4
6/7/2012 23:30914.4VeeamBackup_DCNA-P-VRM-011740.8914.4
6/8/2012 0:00914.4VeeamBackup_DCNA-P-VRM-011740.8914.4

I really wish there was a way to just add Provisoined Spage in GB to the output that comes form the below one liner.

Get-Datastore | Select-Object -Property Name, Datacenter, CapacityGB, FreeSpaceGB | Export-Csv c:\info.csv -NoTypeInformation

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Those different records with the Timestamps are there because the sript by default produces a statistical report over time.

The script can be adapted to only retrieve the most recent statistical values (but note that they still come from Historical Interval 2).

Something like this for example

$metrics = "disk.capacity.latest","disk.provisioned.latest","disk.used.latest" 
$report
= @()
foreach
($ds in Get-Datastore ){   $report += (Get-Stat2 -entity $ds.ExtensionData -stat $metrics -interval "HI2" -MaxSamples 3 |
   
Group-Object -Property Timestamp | %{       New-Object PSObject -Property @{         "Datastore Name" = $ds.Name
        Timestamp = $_.Name
       
"Capacity (GB)" = [Math]::Round(($_.Group |
            where {$_.CounterName -eq "disk.capacity.latest"}).Value/1MB,2)         "Allocated (GB)" = [Math]::Round(($_.Group |
           
where {$_.CounterName -eq "disk.provisioned.latest"}).Value/1MB,2)         "Used (GB)" = [Math]::Round(($_.Group |
           
where {$_.CounterName -eq "disk.used.latest"}).Value/1MB,2)       }     }) } $report | Export-Csv "C:\DS-stats.csv" -NoTypeInformation -UseCulture

Is this producing what you were looking for ?


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

0 Kudos
PorzioM
Contributor
Contributor
Jump to solution

On both of my vCenters I get the following error when running this.

Exception calling "QueryAvailablePerfMetric" with "4" argument(s): "The object has already been deleted or has not been completely created"
At line:139 char:50
+     $metricId = $perfMgr.QueryAvailablePerfMetric <<<< ($Entity.MoRef,$null,$null,$numinterval)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

-Instance parameter invalid for requested stat: disk.capacity.latest.
Valid values are:
At line:164 char:14
+         Throw <<<<  "-Instance parameter invalid for requested stat: $st.`nValid values are: $validInstances"
    + CategoryInfo          : OperationStopped: (-Instance param...id values are: :String) [], RuntimeException
    + FullyQualifiedErrorId : -Instance parameter invalid for requested stat: disk.capacity.latest.
Valid values are:

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Are you running this against vSphere 5 ?


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

0 Kudos
PorzioM
Contributor
Contributor
Jump to solution

running against 4.1

I was actaully able to get the data I needed with the following script

$datastores = get-datastore | get-view

$datastores | select -expandproperty summary | select name, Datacenter, @

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

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

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

sort -Property Name | Export-Csv c:\test.csv -NoTypeInformation

0 Kudos
PorzioM
Contributor
Contributor
Jump to solution

I take that back... the whole script I posted a minute ago works with exception to the Datacenter piece, it does not display the datacenter. Not sure why it is nt showing the datacenter

0 Kudos
LucD
Leadership
Leadership
Jump to solution

So you are in fact not looking for historical data.

Then you can do it even simpler

Get-Datastore | Select Name, Datacenter,CapacityGB,FreeSpaceGB, 
@{N="Provisioned (GB)"; E={[math]::round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB,2) }}| 
Sort-Object -Property Name |
Export-Csv c:\test.csv -NoTypeInformation


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

0 Kudos
PorzioM
Contributor
Contributor
Jump to solution

You are correct, I do not care about historical data. All I wanted was to recreate the output form the Capacity screen on the summary tab of a datastore in a spreadsheet so we can see this info without having to go to every single datastore.

The script I posted works, I tried using the one you posted because it seems more efficient. I ran into a problem with it. I think it may have a typo somewhere. Your right though If I could get this one to work it would be perfect. Thanks Luc!!

Output

Name                                                                                                                              : MyDSName                                                                                                                                                                
Datacenter                                                                                                                       : MyDataCenterName

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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, there was a typo, the @ was missing from the beginning of the calculated properrty.

I updated the code above.


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

0 Kudos
PorzioM
Contributor
Contributor
Jump to solution

Perfect, You rock!!

Cant wait to meet you at VM World this year, if your going. Think you usually speak on PowerCLI.

Thanks.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I'm still waiting to hear if my session proposal is accepted.


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

0 Kudos
AlbertWT
Virtuoso
Virtuoso
Jump to solution

Thanks for sharing here Luc,

is there any reason why the CapacityGB and FreeSpaceGB is empty in the result ?

/* Please feel free to provide any comments or input you may have. */
0 Kudos