PowerCLI

 View Only
  • 1.  Get-Datastore Path Parameter

    Posted May 30, 2009 04:35 AM

    need some assistance with getting nfs datastores information. path/remote host address or name/capacity/free space. can this be done with a oneliner? thank you in advance.



  • 2.  RE: Get-Datastore Path Parameter

    Posted May 30, 2009 05:59 AM

    Sure can.

    Get-Datastore | where {$_.type -eq "NFS"} | Get-View | select @{N="Host"; E={$_.Info.Nas.RemoteHost}},
                                  @{N="Path"; E={$_.Info.Nas.RemotePath}},
    				@{N="Capacity"; E={$_.Info.Nas.Capacity}},
    				@{N="Free"; E={$_.Info.FreeSpace}}
    



  • 3.  RE: Get-Datastore Path Parameter

    Posted May 31, 2009 01:31 AM

    Wow! Excellent, only thing is my path is about 28 character long and was truncated. Thanks LucD!



  • 4.  RE: Get-Datastore Path Parameter
    Best Answer

    Posted May 31, 2009 09:13 AM

    This truncation of output is a PowerShell feature. PS, by default, wants to place the output in a tabular format and wants to make sure that all the output columns fit in the width of your screen.

    That's why some output appears to be truncated on the screen.

    You can find a more complete explanation here in Tobias Weltner's "Mastering PowerShell" series.

    There are several ways of getting the complete properties in your output.

    You could use the Format-Table cmdlet with the -Wrap parameter.

    Get-Datastore | where {$_.type -eq "NFS"} | Get-View | select @{N="Host"; E={$_.Info.Nas.RemoteHost}},
                    @{N="Path"; E={$_.Info.Nas.RemotePath}},
    		  @{N="Capacity"; E={$_.Info.Nas.Capacity}},
    		  @{N="Free"; E={$_.Info.FreeSpace}} | ft -Wrap
    

    See for other methods.



  • 5.  RE: Get-Datastore Path Parameter

    Posted Jun 09, 2009 01:44 AM

    Is it possible to include the host/cluster? with the Get-VMhost command?



  • 6.  RE: Get-Datastore Path Parameter

    Posted Jun 09, 2009 07:29 AM

    This adds the ESX hostname and the clustername.

    If the NFS export is mounted on all ESX hosts in a cluster you will see a line per ESX host in the output.

    $report = @()
    Get-Datastore | where {$_.type -eq "NFS"} | Get-View | %{
    	$ds = $_
    	$_.Host | %{
    	  $row = "" | Select NFSHost, Path, Capacity, Free, ESXHost, Cluster
    	  $row.NFSHost = $ds.Info.Nas.RemoteHost
    	  $row.Path = $ds.Info.Nas.RemotePath
    	  $row.Capacity = $ds.Info.Nas.Capacity
    	  $row.Free = $ds.Info.FreeSpace
    	  $row.ESXHost = (Get-View $_.Key).Name
    	  $row.Cluster = (Get-Cluster | where {$_ | Get-VMHost | where {$_.Name -eq $row.ESXHost}}).Name
    	  $report += $row
    	}
    }
    $report | Sort-Object -property Cluster, ESXHost | ft -wrap
    



  • 7.  RE: Get-Datastore Path Parameter

    Posted Jun 01, 2009 08:05 AM

    Had the same problem and fixed it with www.pathtoolong.com