Axllxa
Contributor
Contributor

Getting VMhost name that is queried when retrieving info on NFS datastores

Jump to solution

Sorry if the question has been already asked,

I'm trying to get the NFS shares present in each ESXi host and the following does the trick

get-datastore | where type -eq "NFS" | select Name

however I'd like to retrieve the name of the host from where the information is retrieved.

Unfortunately I don't see the name of the VMhost among the names when I use get-datastore | get-member.

How could I do that?

Thanks,

Alex

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

Try something like this

foreach($esx in Get-VMHost){
   
Get-Datastore -RelatedObject $esx |
   
Where type -eq "NFS" |
   
Select Name,
       
@{N="VMHost";E={$esx.Name}},
       
@{N="Host";E={$_.Extensiondata.Info.Nas.RemoteHost}},
       
@{N="Mount point";E {$_.Extensiondata.Info.Nas.RemotePath}}
}

One way to see what properties are on an object is like this

$ds = Get-Datastore -Name DS1
$ds.ExtensionData | Format-Custom -Depth 3


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

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership

Have a look at 1.  Re: NFS mount properties


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

Axllxa
Contributor
Contributor

Hi Lucd,

thanks for your answer. Indeed the other thread is useful.

PowerCLI C:\> get-datastore | where type -eq "NFS" | select Name,@{N="Host";E={$_.Extensiondata.Info.Nas.RemoteHost}}, @{N="Mount point";E {$_.Extensiondata.Info.Nas.RemotePath}}

Name                                              Host                                              Mount point

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

server02:ds00-util                                server02                                          /zpool02/datastores/ds00-util

server02:ds00-util                                10.42.0.5                                         /zpool02/datastores/ds00-util

ds00-util                                            10.42.16.5                                        /zpool02/datastores/ds00-util

server02:ds00-util                                10.42.0.5                                         /zpool02/datastores/ds00-util

However since I query multiple ESXi hosts at the same time (VM01,VM02,VM03,etc) I'd like to know from which of the them each line of the output refers to so that if there are discrepancy from the original design I know where to intervene.

Also how to get which other options than Extensiondata.Info.Nas.RemotePath the $_ has got? Is there way like get-member?

Many thanks,

Alex

0 Kudos
LucD
Leadership
Leadership

Try something like this

foreach($esx in Get-VMHost){
   
Get-Datastore -RelatedObject $esx |
   
Where type -eq "NFS" |
   
Select Name,
       
@{N="VMHost";E={$esx.Name}},
       
@{N="Host";E={$_.Extensiondata.Info.Nas.RemoteHost}},
       
@{N="Mount point";E {$_.Extensiondata.Info.Nas.RemotePath}}
}

One way to see what properties are on an object is like this

$ds = Get-Datastore -Name DS1
$ds.ExtensionData | Format-Custom -Depth 3


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

0 Kudos
Axllxa
Contributor
Contributor

Excellent 🙂

Thank you!

0 Kudos