VMware Cloud Community
pamiller21
Enthusiast
Enthusiast
Jump to solution

Datastore Capacity Load

Hey all,

Looking if anyone has a script to use the total disk used to calculate the percent load on each datastore in a DC and export in a html page.

Any tips would be great,

Andy

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Like this?

$Header = @"

<style>

TABLE {border-width: 1px; border-style: solid; border-color: black; border-collapse: collapse;}

TH {border-width: 1px; padding: 3px; border-style: solid; border-color: black; background-color: #6495ED;}

TD {border-width: 1px; padding: 3px; border-style: solid; border-color: black;}

</style>

"@

$dcName = 'DC1'

$ds = Get-Datacenter -Name $dcName | Get-Datastore |

  where {$_.Type -eq 'VMFS' -and $_.ExtensionData.Summary.MultipleHostAccess}

$totalSpaceUsed = $ds | % {$_.CapacityGB - $_.FreeSpaceGB} | Measure-Object -Sum | select -ExpandProperty Sum

Get-Stat -Entity $ds -Stat 'disk.used.latest' -Realtime -MaxSamples 1 -Instance '' |

  ForEach-Object -Process {

  New-Object PSObject -Property @{

   Datastore   = $_.Entity.Name

   PercentofTotalSpaceGB = [math]::Round(($_.Value / 1MB) / $totalSpaceUsed * 100, 1)

  }

} |

  Sort-Object -Property Datastore |

  Select Datastore, PercentofTotalSpaceGB |

  ConvertTo-Html -Head $Header |

  Out-File -FilePath .\report.html

Invoke-Item -Path .\report.html


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

View solution in original post

5 Replies
LucD
Leadership
Leadership
Jump to solution

You mean something like this Datastore Usage Statistics


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

pamiller21
Enthusiast
Enthusiast
Jump to solution

Not sure this is what I am looking for.  I would like a comparison showing each datastore and the percentage of how much space is used in comparison to all space used in the DC.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You mean something like this?

$Header = @"

<style>

TABLE {border-width: 1px; border-style: solid; border-color: black; border-collapse: collapse;}

TH {border-width: 1px; padding: 3px; border-style: solid; border-color: black; background-color: #6495ED;}

TD {border-width: 1px; padding: 3px; border-style: solid; border-color: black;}

</style>

"@

$ds = Get-Datastore | where{$_.ExtensionData.Summary.MultipleHostAccess}

$totalSpaceUsed = $ds | %{$_.CapacityGB - $_.FreeSpaceGB} | Measure-Object -Sum | select -ExpandProperty Sum

Get-Stat -Entity $ds -Stat 'disk.used.latest' -Realtime -MaxSamples 1 -Instance '' |

ForEach-Object -Process {

    New-Object PSObject -Property @{

        Datastore = $_.Entity.Name

        PercentofTotalSpaceGB = [math]::Round(($_.Value/1MB)/$totalSpaceUsed*100,1)

    }

} |

Sort-Object -Property Datastore |

Select Datastore, PercentofTotalSpaceGB |

ConvertTo-Html -Head $Header |

Out-File -FilePath .\report.html

Invoke-Item -Path .\report.html


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

pamiller21
Enthusiast
Enthusiast
Jump to solution

This seems to be right on, but I need to target a DC one at a time, not all together.  Also it shows the NFS datastores used for ISOs, can we put in a ignore line?

LucD
Leadership
Leadership
Jump to solution

Like this?

$Header = @"

<style>

TABLE {border-width: 1px; border-style: solid; border-color: black; border-collapse: collapse;}

TH {border-width: 1px; padding: 3px; border-style: solid; border-color: black; background-color: #6495ED;}

TD {border-width: 1px; padding: 3px; border-style: solid; border-color: black;}

</style>

"@

$dcName = 'DC1'

$ds = Get-Datacenter -Name $dcName | Get-Datastore |

  where {$_.Type -eq 'VMFS' -and $_.ExtensionData.Summary.MultipleHostAccess}

$totalSpaceUsed = $ds | % {$_.CapacityGB - $_.FreeSpaceGB} | Measure-Object -Sum | select -ExpandProperty Sum

Get-Stat -Entity $ds -Stat 'disk.used.latest' -Realtime -MaxSamples 1 -Instance '' |

  ForEach-Object -Process {

  New-Object PSObject -Property @{

   Datastore   = $_.Entity.Name

   PercentofTotalSpaceGB = [math]::Round(($_.Value / 1MB) / $totalSpaceUsed * 100, 1)

  }

} |

  Sort-Object -Property Datastore |

  Select Datastore, PercentofTotalSpaceGB |

  ConvertTo-Html -Head $Header |

  Out-File -FilePath .\report.html

Invoke-Item -Path .\report.html


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