prateekpatalVCP
Enthusiast
Enthusiast

Datastore report-Powercli script

Jump to solution

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

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

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

prateekpatalVCP
Enthusiast
Enthusiast

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
0 Kudos
LucD
Leadership
Leadership

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

0 Kudos
vmk2014
Expert
Expert

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

0 Kudos
LucD
Leadership
Leadership

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


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

0 Kudos
vmk2014
Expert
Expert

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

0 Kudos
LucD
Leadership
Leadership

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

LucD,

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

thanks

v

0 Kudos
LucD
Leadership
Leadership

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

0 Kudos
vmk2014
Expert
Expert

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

0 Kudos
LucD
Leadership
Leadership

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

Thank LucD. It worked for me

0 Kudos