Pages: [1]
Print
Author Topic: List datastore information for each cluster  (Read 1993 times)
esarakaitis
Administrator
Sr. Member
*****
Posts: 256


8223109 sack57@hotmail.com littleking57 rootinfortwayne
View Profile WWW Email
« on: January 30, 2009, 02:10:26 PM »

Code:
$clusters = get-cluster
aforeach ($cluster in $clusters)
{
    $vmhosts = $cluster | get-vmhost
    $firsthost = $vmhosts[0]
    $datastores = $firsthost | get-datastore | % {(Get-View $_.ID).summary}
    foreach ($datastore in $datastores)
    {
        $datastore | select-object @{Name = "Date"; Expression = {get-date}}, @{Name = "Cluster"; Expression = {$cluster.name}}, URL, Name, Freespace, Capacity
           }
        }
Logged
racerzer0
Newbie
*
Posts: 1


View Profile Email
« Reply #1 on: March 27, 2009, 09:27:08 AM »

How can I modify this script to provide me with total datastore capacity (used + free) per cluster?

Logged
ewannema
Administrator
Newbie
*****
Posts: 33


View Profile WWW
« Reply #2 on: March 27, 2009, 01:41:20 PM »

If that is all the information you need you can let PowerShell add up the data for you.

I also added a little bit more error checking.

Code:
foreach ($cluster in Get-Cluster)
{
    $vmhosts = @($cluster | Get-VMHost)
   
    # Skip to the next cluster if there were no hosts in this one.
    if ($vmhosts.Length -eq 0)
    {
        continue
    }
    $firsthost = $vmhosts[0]
    $totalCapacity = ($firsthost | Get-Datastore | Measure-Object -Property CapacityMb -Sum).Sum
    $cluster | Select-Object Name, @{Name="TotalCapacityMb"; Expression={$totalCapacity}}
}

Logged
Pages: [1]
Print
Jump to: