VMware Cloud Community
prateekpatalVCP
Enthusiast
Enthusiast
Jump to solution

Datastore report-Powercli script

Hi All,

I am looking for a script which can fetch datastore usage in percentage. i have one script and i am getting the report as below in percentage free space, instead i need the data in percentage with total usage in percentage.

DataStoreNamePercentage Free Space(%)
datastore192.07
datastore271.59
datastore371.6
datastore475.19

thanks in advance

Prateek
Tags (1)
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try like this

Get-Datastore |

Select Name,

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

---------------------------------------------------------------------------------------------------------

Was it helpful? Let us know by completing this short survey here.


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

View solution in original post

12 Replies
LucD
Leadership
Leadership
Jump to solution

Try like this

Get-Datastore |

Select Name,

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

---------------------------------------------------------------------------------------------------------

Was it helpful? Let us know by completing this short survey here.


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

prateekpatalVCP
Enthusiast
Enthusiast
Jump to solution

Thank you very mush  LucD,

One more thing, can we add below script with the percentage usage :

get-datastore | select-object name,@{Label=”FreespaceGB”;E={“{0:n2}” -f ($_.FreespaceGB)}}, CapacityGB, @{Label=”Provisioned”;E={“{0:n2}” -f ($_.CapacityGB – $_.FreespaceGB +($_.extensiondata.summary.uncommitted/1GB))}}|sort name | export-csv datastores.csv

So that i  could get the below output:

NameFreespaceGBCapacityGBProvisionedUsed Space %

thanks

prateek

Prateek
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sure, but that is just adding properties on the same Select-Object.

Like this

Get-Datastore |

Select Name,

   @{N=”FreespaceGB”;E={{0:n2}-f ($_.FreespaceGB)}},

  CapacityGB,

   @{N=”Provisioned”;E={{0:n2}-f ($_.CapacityGB$_.FreespaceGB +($_.extensiondata.summary.uncommitted/1GB))}},

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


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

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

Hi LucD,

I tried below script but it throws an error

PS D:\vmk> .\Datastore.ps1

At D:\vmk\Datastore-freespace.ps1:1 char:5

+ $Get-Datastore |

+     ~~~~~~~~~~

Unexpected token '-Datastore' in expression or statement.

    + CategoryInfo          : ParserError: (:) [], ParseException

    + FullyQualifiedErrorId : UnexpectedToken

thanks

vmk

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That dollar-sign ($) in front of Get-Datastore shouldn't be there


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

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

LucD,

Sorry for late reply. i'll check and will let you know. But if want to know the specific data store utilization example _VMAX_WIN and Oracle_VMAX_ then how to get the report for utilization and % percentage free. Kindly help me

thanks

v

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can use the Name parameter on the Get-Datastore cmdlet.

$dsNames = '*_VMAX_WIN*','*Oracle_VMAX_*'

Get-Datastore -Name $dsNames |

Select Name,

   @{N=”FreespaceGB”;E={{0:n2}-f ($_.FreespaceGB)}},

  CapacityGB,

   @{N=”Provisioned”;E={{0:n2}-f ($_.CapacityGB$_.FreespaceGB +($_.extensiondata.summary.uncommitted/1GB))}},

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


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

vmk2014
Expert
Expert
Jump to solution

LucD,

it's working fine. is it possible to add % free space along with data used % (already added) ?

thanks

v

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this

$dsNames = '*_VMAX_WIN*','*Oracle_VMAX_*'

Get-Datastore -Name $dsNames |

Select Name,

   @{N=”FreespaceGB”;E={{0:n2}-f ($_.FreespaceGB)}},

   CapacityGB,

   @{N=”Provisioned”;E={{0:n2}-f ($_.CapacityGB$_.FreespaceGB +($_.extensiondata.summary.uncommitted/1GB))}},

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

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


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

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

Hi LucD,

When i tried to export into csv format but it throws an error. Any idea why ?

pastedImage_0.png

Get-Datastore |

Select Name,

   @{N=”FreespaceGB”;E={“{0:n2}” -f ($_.FreespaceGB)}},

  CapacityGB,

   @{N=”Provisioned”;E={“{0:n2}” -f ($_.CapacityGB – $_.FreespaceGB +($_.extensiondata.summary.uncommitted/1GB))}},

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

$report | Export-Csv -path c:\Temp\dsreport-Marc19.csv

Thanks

V

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I'm not sure why you are using the $report variable, but try like this

Get-Datastore |

Select-Object Name,

    @{N = ”FreespaceGB”; E = {{0:n2}-f ($_.FreespaceGB) } },

    CapacityGB,

    @{N = ”Provisioned”; E = {{0:n2}-f ($_.CapacityGB$_.FreespaceGB + ($_.extensiondata.summary.uncommitted / 1GB)) } },

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

Export-Csv -path c:\Temp\dsreport-Marc19.csv


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

vmk2014
Expert
Expert
Jump to solution

Thank LucD. It worked for me

Reply
0 Kudos