Automation

 View Only
  • 1.  How to get list of virtual disk?

    Posted Jul 20, 2012 10:18 AM

    Hello

    How can i retrieve the list of virtual disk with information like size, used, free, type ?

    ==================This is my code ========================================

    Object cmobj
    = cb.getServiceUtil().GetDynamicProperty(hostmor, "configManager");

                        HostConfigManager configMgr = (HostConfigManager)cmobj;

    ManagedObjectReference ssSystem = configMgr.storageSystem;

    HostStorageDeviceInfo storageInfo = (HostStorageDeviceInfo)cb.getServiceUtil().GetDynamicProperty(ssSystem,

                                                                            "storageDeviceInfo");

    ======================================================================

    I can get some information from sotrageInfo, but it is not what i need, i mean, i cannot get "size, used, free, type, etc" informations.

    And i tried the code below also:

    dcmor = ecb.getServiceUtilV25().GetDecendentMoRefs(_sic.virtualDiskManager, "Datastore");

    But i get nothing

    Someone could help me?



  • 2.  RE: How to get list of virtual disk?
    Best Answer

    Posted Jul 20, 2012 11:43 AM

    I think that you are looking for information about datastores. You can try the following PowerCLI command:

    Get-Datastore |
    Select-Object -Property Name,CapacityMB,
    @{Name="UsedSpaceMB";Expression={$_.CapacityMB-$_.FreeSpaceMB}},
    FreeSpaceMB,Type
    
    

    If you are after information about virtual machine disks then you can use the following script:

    Get-VM |
    ForEach-Object {
      $VM = $_
      $VM.Guest.Disks |
      Add-Member -MemberType NoteProperty -Name VM -Value $VM.Name -PassThru |
      Select-Object -Property VM,Path,
        @{Name="CapacityGB";Expression={"{0:N1}" -f ($_.Capacity/1GB)}},
        @{Name="UsedSpaceGB";Expression={"{0:N1}" -f (($_.Capacity-$_.FreeSpace)/1GB)}},
        @{Name="FreeSpaceGB";Expression={"{0:N1}" -f ($_.FreeSpace/1GB)}}
    }
    
    

    Regards, Robert



  • 3.  RE: How to get list of virtual disk?

    Posted Jul 20, 2012 11:50 AM

    Thanks a lot,

    But i'm using C#

    And i think i posted in a wrong place..

    And i found how to get the basic information with using C# 

    :smileyhappy: