VMware Cloud Community
jumcco
Contributor
Contributor
Jump to solution

Using Get-View and LinkedView to show missing connections to datastores in datastore clusters

I'm trying to write a small PowerCLI function to show which hosts are missing datastore connections in a datastore clusters. This is the same information you see in the web client when going to the DatastoreCluster -> Monitor Tab -> Connectivity -> Clusters & click on one of the clusters. It then shows each host in the cluster, number of datastores mounted, and any details (such as missing connection to XYZ).

I was trying to do it with Get-View using the LinkedView and UpdateViewData calls, but I'm having a bit of trouble. I'm able to get the DatastoreCluster, and I can parse through each individual datastore. The problem I'm running into is I'm only able to find the associated host's moref, and not the LinkedView data that would give me the hostname instead. I know I can get it with a (Get-VMHost -ID $moref).Name, but I was thinking that would be less efficient/slower than doing it with the Get-View / LinkedView / UpdateViewData route. I'd like to be able to do something along the lines of:

$DSView.Host[0].Name

$DSView.LinkedView.Host[0].Name

###############

$DatastoreCluster="MyDatastoreClusterName";

$DSClusterView = Get-View -ViewType StoragePod -Filter @{"Name"="^$DatastoreCluster$"} -Property Name;

$DSClusterView.UpdateViewData("ChildEntity.Name");

$DSClusterName = $DSClusterView.Name;

# Select the first datastore in the datastorecluster

$DSView = $DSClusterView.LinkedView.ChildEntity[0];

$DSView.UpdateViewData("Host")

# Print the name of the datastore

$DSView.Name;

# Show all hosts that have this datastore mounted:

$DSView.Host

#####

PowerCLI C:\> $DSView.Host[0]

Key                  MountInfo                LinkedView

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

HostSystem-host-4302 VMware.Vim.HostMountInfo

PowerCLI C:\> (Get-VMHost -id ($DSView.Host[0].Key)).Name

myesxhost.some.fqdn.com

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Can't you do this as follows?

$DatastoreCluster="MyDatastoreClusterName"

$DSClusterView = Get-View -ViewType StoragePod -Filter @{"Name"="^$DatastoreCluster$"} -Property Name,ChildEntity

$DSCDatastores = Get-View -Id $DSClusterView.ChildEntity -Property Name,Host

# Show all hosts that have this datastore mounted:

foreach($ds in $DSCDatastores){

    Get-View -Id $ds.Host.Key -Property Name |

    Select @{N='DSC';E={$DatastoreCluster}},

        @{N='Datastore';E={$ds.Name}},

        @{N='VMHost';E={$_.Name}}

}


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

View solution in original post

2 Replies
LucD
Leadership
Leadership
Jump to solution

Can't you do this as follows?

$DatastoreCluster="MyDatastoreClusterName"

$DSClusterView = Get-View -ViewType StoragePod -Filter @{"Name"="^$DatastoreCluster$"} -Property Name,ChildEntity

$DSCDatastores = Get-View -Id $DSClusterView.ChildEntity -Property Name,Host

# Show all hosts that have this datastore mounted:

foreach($ds in $DSCDatastores){

    Get-View -Id $ds.Host.Key -Property Name |

    Select @{N='DSC';E={$DatastoreCluster}},

        @{N='Datastore';E={$ds.Name}},

        @{N='VMHost';E={$_.Name}}

}


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

jumcco
Contributor
Contributor
Jump to solution

That should do the trick, thanks LucD.

Reply
0 Kudos