Powershell 如何获取子属性

Powershell 如何获取子属性,powershell,vmware,powercli,Powershell,Vmware,Powercli,使用VMWare PowerCLi,我尝试从变量访问属性,但不确定如何获取,到目前为止,我的代码如下所示: $datastore = Get-Datastore | where {$_.name -like "*geko*"} | select name,remotehost, remotepath | Sort-Object name | ft -AutoSize $datastore 所以我得到的结果是: Name RemoteHost

使用VMWare PowerCLi,我尝试从变量访问属性,但不确定如何获取,到目前为止,我的代码如下所示:

    $datastore = Get-Datastore | where {$_.name -like "*geko*"} | select 
    name,remotehost, remotepath | Sort-Object name | ft -AutoSize
    $datastore
所以我得到的结果是:

Name            RemoteHost        RemotePath      
----            ----------        ----------      
Serv_Geko       {192.168.134.137} /Serv_Geko
问题是如何获取变量中的RemotePath,或者如何从上面的$datastore变量访问它

我想我可以从
$datastore.RemoteHost
中获取它,但这似乎不起作用

我基本上只需要将IP放入一个变量中,这样我就可以在脚本的底层使用它


非常感谢您的帮助

从代码中删除
ft-AutoSize
,然后您可以访问
$datastore.RemoteHost

PS> $datastore = Get-Datastore | where {$_.name -like "*geko*"} | select 
    name, remotehost, remotepath | Sort-Object name
PS> $datastore.RemoteHost

使用
选择对象的
-ExpandProperty
参数

$IPAddress = Get-Datastore | where {$_.name -like "*geko*"} | select-object -ExpandProperty remotehost
现在您的
$IPAddress

包含IP地址。

什么是
$datastore.RemoteHost
的输出?
$NewVariable=$datastore.RemotePath