VMware Cloud Community
Breakin
Contributor
Contributor
Jump to solution

Generating report via PowerCLI

Hi,

i am trying to generate report of hosted VMs via PowerCLI generating a csv file. Here is the code:

Connect-VIServer SERVERNAMEHERE

$allvminfo = @()

$vms = get-vm

foreach($vm in $vms){

$vminfo = "" | Select Name, folder, Host, PowerState, CPUCount, RAMAssigned, ProvisionedSpace, UsedSpace, UnusedSpace

$VMPowerState = Get-VM $vm.Name | select PowerState

$VMPowerState = $VmPowerState.PowerState

$CPUCount = Get-VM $vm.Name | select NumCpu

$CPUCount = $CPUCount.NumCpu

$RAMAssigned = Get-VM $vm.Name | select MemoryMB

$RAMAssigned = $RAMAssigned.MemoryMB

$vmview = Get-VM $vm.Name | Get-View

$ProvisionedSpace = Get-VM $vm.Name | select ProvisionedSpaceGB

$ProvisionedSpace = $ProvisionedSpace.ProvisionedSpaceGB

$ProvisionedSpace = [math]::round($ProvisionedSpace, 2)

$ProvisionedSpace =$ProvisionedSpace.ToString()

$ProvisionedSpace = $ProvisionedSpace + " GB"

$UsedSpace = Get-VM $vm.Name | select UsedSpaceGB

$UsedSpace = $UsedSpace.UsedSpaceGB

$UsedSpace = [math]::round($UsedSpace, 2)

$UsedSpace =$UsedSpace.ToString()

$UsedSpace = $UsedSpace + " GB"

                $vminfo.Name = $vm.Name

                $vminfo.folder = $vm.folder

                $vminfo.Host = $VMHost

                $vminfo.PowerState = $VMPowerState

                $vminfo.CPUCount = $CPUCount

                $vminfo.RAMAssigned = $RAMAssigned

                $vminfo.ProvisionedSpace = $ProvisionedSpace

                $vminfo.UsedSpace = $UsedSpace

                $allvminfo += $vminfo

}

$allvminfo | Select Name, folder, PowerState, CPUCount, RAMAssigned, ProvisionedSpace, UsedSpace | Export-Csv "C:\temp\VMs.csv" -noTypeInformation

the question is: what am i doing wrong?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

From the 1st screenshot it looks as if your vSphere server connection times out rather quickly.

What interval is set ?

Do a Get-PowerCLIConfiguration


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
2 Replies
Breakin
Contributor
Contributor
Jump to solution

here are the screenshots

0 Kudos
LucD
Leadership
Leadership
Jump to solution

From the 1st screenshot it looks as if your vSphere server connection times out rather quickly.

What interval is set ?

Do a Get-PowerCLIConfiguration


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos