Quantcast
Channel: VMware Communities : All Content - VMware PowerCLI
Viewing all articles
Browse latest Browse all 16717

Single row for capacity disk

$
0
0

Hi guys,

 

I customized a script for VM inventory for my requirement. Its working fine. But depending on the number of disk in vm , I get that amount of rows as result.

 

For example: If VM1 has 2 disks...The output also has 2 rows for each disk for vm1.

 

Is it possible to get total capacity in a single row, rather than separate disks in multiple rows?

 

 

Here is the script I tried:

 

$sView = @{

    ViewType = 'VirtualMachine'

    Property = 'Name','runtime.powerState','Guest.hostname','Guest.net','Config.Hardware.numCPU','Summary.Storage.Committed','Summary.Storage.UnCommitted','Config.Hardware.MemoryMB','Runtime.Host','Guest.GuestFullName','Config.Hardware.Device','Config.version','guest.toolsversionstatus','Parent','ResourcePool'

    Filter = @{Name = '^((?!replica).)*$'}

}

$vms = Get-View @sView

foreach($vm in $vms)

{

    $t = Get-View $vm.ResourcePool -Property Name,Parent

    $datacenter = $t.Name

    $vm.Config.Hardware.Device | where {$_.GetType().Name -eq "VirtualDisk"} |

    Select  @{N="VMName";E={$vm.Name}},

 

    @{N="Hostname";E={$vm.guest.hostname}},

 

    @{N='IP Address';E={[string]::Join(',',($vm.Guest.Net | %{$_.IpAddress | where{$_.Split('.').Count -eq 4} | %{$_}}))}},

 

    @{N='OS';E={$vm.Guest.GuestFullName}},

 

    @{N='Host';E={$script:esx = Get-View -Id $vm.Runtime.Host; $script:esx.name}},

 

    @{N='Status';E={$vm.runtime.powerState}},

 

    @{N='CPU';E={$vm.config.Hardware.NumCpu}},

 

    @{N='RAM';E={$vm.Config.Hardware.MemoryMB| %{[math]::Round($_/1kb,2)}}},

 

    @{N="Disk capacity GB";E={$_.CapacityInKB| %{[math]::Round($_/1MB,2)}}},

 

    @{N="Disk datastore";E={$_.Backing.Filename.Split(']')[0].TrimStart('[')}},

 

    @{N="Disk Type";E={if($_.Backing.ThinProvisioned){'Thin'}

    else{'Thick'}}},

 

   @{N="TotalHDD"; E={($vm.Config.Hardware.Device | where{$_ -is [VMware.Vim.VirtualDisk]}).Count}},

 

   @{N="Disk Provision GB";E={$vm.Summary.Storage.UnCommitted| %{[math]::Round($_/1GB,2)}}},

 

    @{N="Disk Used GB";E={$vm.Summary.Storage.Committed| %{[math]::Round($_/1GB,2)}}},

 

   @{N="HW Version";E={$vm.Config.version}},

 

   @{N="Tools Status";E={$vm.guest.toolsversionstatus}}

 

 

}

 

###################End of script###########################

 

Any help?


Viewing all articles
Browse latest Browse all 16717


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>