Automation

 View Only
  • 1.  Generating report via PowerCLI

    Posted Mar 24, 2015 01:43 PM

    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?



  • 2.  RE: Generating report via PowerCLI

    Posted Mar 24, 2015 01:50 PM

    here are the screenshots



  • 3.  RE: Generating report via PowerCLI
    Best Answer

    Posted Mar 24, 2015 01:54 PM

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

    What interval is set ?

    Do a Get-PowerCLIConfiguration