VMware Cloud Community
comiscience
Contributor
Contributor
Jump to solution

How to get list of virtual disk?

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?

Reply
0 Kudos
1 Solution

Accepted Solutions
RvdNieuwendijk
Leadership
Leadership
Jump to solution

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

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition

View solution in original post

Reply
0 Kudos
2 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

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

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos
comiscience
Contributor
Contributor
Jump to solution

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# 

Smiley Happy

Reply
0 Kudos