Pages: [1]
Print
Author Topic: Validate that all cluster datastores are visable  (Read 942 times)
esarakaitis
Administrator
Sr. Member
*****
Posts: 256


8223109 sack57@hotmail.com littleking57 rootinfortwayne
View Profile WWW Email
« on: February 19, 2009, 07:35:37 AM »

Code:
# For each cluster
foreach ($cluster in Get-Cluster)
{
    # Get the hosts
    $vmhosts = $cluster | Get-VMHost

    # Skip to the next cluster if there were no hots defined.
    if (!$vmhosts)
    {
        continue
    }
   
    $master_ds_list = @{}
    # Treat the first one as authoritative and create the master list
    foreach ($datastore in ($vmhosts[0] | Get-Datastore))
    {
        $master_ds_list[$datastore.Name] = "Missing"
    }
   
    # Evaluate the hosts.  Process the first host again just to make sure
    # the report is complete.
    foreach ($vmhost in $vmhosts)
    {
        # Copy the master list
        $test_ds_list = @{} + $master_ds_list
       
        foreach ($ds in ($vmhost | Get-Datastore))
        {
            # If the datastore is in the test list it is ok.
            # otherwise it is extra.
            if ($test_ds_list.ContainsKey($ds.name))
            {
                $test_ds_list[$ds.name] = "Ok"
            }
            else
            {
                $test_ds_list[$ds.name] = "Extra"
            }
        }
       
        # Output results
        foreach ($key in $test_ds_list.Keys)
        {
            $key | Select-Object @{Name="Cluster"; Expression={$cluster.Name}}, `
                                 @{Name="Host"; Expression={$vmhost}}, `
                                 @{Name="Datastore"; Expression={$key}},
                                 @{Name="Status"; Expression={$test_ds_list[$key]}}
        }
    }
}
Logged
Pages: [1]
Print
Jump to: