PowerCLI

 View Only
  • 1.  Get datastore name and canonical name

    Posted Jul 26, 2018 06:22 AM

    Hello,

    I just to list the datastore friendly name along with the canonical name please. I've previewed this topic, but that's not what I need.



  • 2.  RE: Get datastore name and canonical name
    Best Answer

    Posted Jul 26, 2018 07:15 AM

    Is this returning what you are looking for?

    Get-Datastore |

    Select Name,@{N='CanonicalName';E={$_.Extensiondata.Info.Vmfs.Extent[0].DiskName}}



  • 3.  RE: Get datastore name and canonical name

    Posted Jul 26, 2018 07:28 AM

    Excellent. Thank you.

    I have a question please, I've always wanted to learn about this thing "{$_.Extensiondata.Info.Vmfs.Extent[0].DiskName}}", what do you call that kind of syntax, and where can I find a guide to that kind of properties for all of the vSphere objects?



  • 4.  RE: Get datastore name and canonical name

    Posted Jul 26, 2018 07:44 AM

    In short, there are 2 types of objects accessible through PowerCLI.

    1. The PowerCLI .Net objects. These are returned by PowerCLI cmdlets, and contain a selected set of properties (by the PowerCLI Dev Team).
    2. The vSphere objects. These are read-only copies of the objects that are used internally by vSphere servers. They are documented in the vSphere Web Services API Reference

    The objects of type 2 can be retrieved by the Get-View cmdlet. For example:

    Note that the Filter parameter expects a hash table of conditions, where the right-side operand of each key-value pair is a RegEx expression.

    Get-View -ViewType VirtualMachine -Filter @{'Name'='^MyVM$'}

    Or through the ExtensionData property of objects of type 1. For example

    Get-VM -Name MyVM | Select -ExpandProperty ExtensionData

    These 2 lines return the same VirtualMachine object.