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?