VMware Cloud Community
MrSulik
Contributor
Contributor
Jump to solution

How to read VM ProvisionedSpaceGB and UsedSpaceGB by using get-view?

Hello,

I would like to retrieve the VM properties ProvisionedSpaceGB and UsedSpaceGB by using get-view and not get-vm.

How do I do that?

Thanks a lot in advance!

Regards,

André

1 Solution

Accepted Solutions
mattboren
Expert
Expert
Jump to solution

Hello, André-

You can retrieve a few properties of a VirtualMachine View object, and then make a couple of calculated properties, like:

## get the View object of this VM, with a choice few properties (faster), then select some info about the object
Get-View -ViewType VirtualMachine -Filter @{"Name" = "^myVM0$"} -Property Name,Summary.Storage |
   
Select Name,
        @{n
="ProvisionedSpaceGB"; e={($_.Summary.Storage.Committed + $_.Summary.Storage.Uncommitted) / 1GB}},
        @{n
="UsedSpaceGB"; e={$_.Summary.Storage.Committed / 1GB}}

The point of just getting those few properties in the Get-View call is lower memory usage in the PowerShell session, and much higher speed in retrieving the View object (without specifying particular properties to retrieve, the cmdlet returns all available properties). How does that do for you?

View solution in original post

2 Replies
mattboren
Expert
Expert
Jump to solution

Hello, André-

You can retrieve a few properties of a VirtualMachine View object, and then make a couple of calculated properties, like:

## get the View object of this VM, with a choice few properties (faster), then select some info about the object
Get-View -ViewType VirtualMachine -Filter @{"Name" = "^myVM0$"} -Property Name,Summary.Storage |
   
Select Name,
        @{n
="ProvisionedSpaceGB"; e={($_.Summary.Storage.Committed + $_.Summary.Storage.Uncommitted) / 1GB}},
        @{n
="UsedSpaceGB"; e={$_.Summary.Storage.Committed / 1GB}}

The point of just getting those few properties in the Get-View call is lower memory usage in the PowerShell session, and much higher speed in retrieving the View object (without specifying particular properties to retrieve, the cmdlet returns all available properties). How does that do for you?

MrSulik
Contributor
Contributor
Jump to solution

Hello mattboren,

that works perfectly!

Thanks a lot!

Yes, that's the reason why I'm looking for get-view equivalents to get-vm.

I'm currently writing a reporting script and the speed gains and memory savings are really dramatic.

I'm just struggeling sometimes in finding the properties I need in the SDK when using get-view.

I thought those two properties were fixed and don't need to be calculated. No wonder, I couldn't find them.

Regards,

André

0 Kudos