This script will report on the RAM, cores, total disk space.
#parameters $output_path = "c:\Users\frank\Documents\" $vmhost = "my-hyp1" $vms=get-vm -ComputerName $vmhost; # Loop through each VM found #path to save the result $outputfile = $output_path + "vms_report_" + $vmhost + ".csv" #"VMname,VMRAM(MB),VMcores,Total VMdisksize(GB)"> $outputfile echo "VMname, VMRAM(MB), VMcores, Total VMdisksize(GB)"; #new way to create csv part 1 - generate header ##this bit creates the CSV if it does not already exist $headers = "VMname", "VMRAM(MB)", "VMcores", "Total VMdisksize(GB)" $psObject = New-Object psobject foreach($header in $headers) { Add-Member -InputObject $psobject -MemberType noteproperty -Name $header -Value "" } $outputfile_tmp = $output_path + "vms_report_" + $vmhost + "temp.csv" $psObject | Export-Csv $outputfile_tmp -NoTypeInformation #remove the empty row Get-Content $outputfile_tmp | Select-Object -SkipLast 1 | Set-Content $outputfile -Encoding UTF8 Remove-item $outputfile_tmp #end of new way to create csv part 1 foreach ($vm in $vms) { # Get VM details $vmname = $vm.name; $vmram = [math]::round((($VM | get-vmmemory).Startup/1024/1024)) ; $totalcores = ($vm | Get-VMProcessor).Count; #get disk size $vmDisks = Get-VHD -ComputerName $vmhost -VMId $vm.VMId -ErrorAction SilentlyContinue -ErrorVariable getVhdErr $vmDisktotalsize = 0 foreach($vmDisk in $vmDisks) { $vmDiskMaxSize = [math]::round($vmDisk.Size/1024/1024/1024) $vmDisktotalsize=+$vmDiskMaxSize } # Build CSV output #$out = $vmname + "," + $vmram + "," + $totalcores + "," +$vmDisktotalsize; #echo $out # Output to file #$out >> $outputfile; ##new way to create csv part2 - append data #this bit appends a new row to the CSV file $hash = @{ "VMname" = $vmname "VMRAM(MB)" = $vmram "VMcores" = $totalcores "Total VMdisksize(GB)" = $vmDisktotalsize } $newRow = New-Object PsObject -Property $hash Export-Csv $outputfile -inputobject $newrow -append -Force ##end of new way part2 }