VMware Cloud Community
steve31783
Enthusiast
Enthusiast
Jump to solution

Need help w/VM report script

I am fairly new to PS, and am trying to use a script I found at

Here is the script:

Get-VIServer -Server 192.168.1.1 -User admin -Password admin

$Report = @()

get-vm | % {

$vm = Get-View $_.ID

$ReportRow = "" | Select-Object VMName, Hostname, OS, IPAddress, VMState, TotalCPU, TotalMemory, MemoryUsage, TotalNics, ToolsStatus, ToolsVersion, MemoryLimit, MemoryReservation

$ReportRow.VMName = $vm.Name

$ReportRow.HostName = $vm.guest.hostname

$ReportRow.OS = $vm.guest.guestFullName

$ReportRow.IPAddress = $vm.guest.ipAddress

$ReportRow.VMState = $vm.summary.runtime.powerState

$ReportRow.TotalCPU = $vm.summary.config.numcpu

$ReportRow.TotalMemory = $vm.summary.config.memorysizemb

$ReportRow.MemoryUsage = $vm.summary.quickStats.guestMemoryUsage

$ReportRow.TotalNics = $vm.summary.config.numEthernetCards

$ReportRow.ToolsStatus = $vm.guest.toolsstatus

$ReportRow.ToolsVersion = $vm.config.tools.toolsversion

$ReportRow.MemoryLimit = $vm.resourceconfig.memoryallocation.limit

$ReportRow.MemoryReservation = $vm.resourceconfig.memoryallocation.reservation

$Report += $ReportRow

}

$Report | Export-CSV c:\export.csv

The script is able to connect to my VC, however no data returns. Am I doing something wrong?

I seem to have a similar issue when testing any script that has "$vm = Get-View $_.ID" in it...

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Did you try stopping/starting the application (VI Toolkit prompt, PowerShell+...) from where you run the script ?

Does this return anything ?

Get-VM | %{Get-View $_.ID}


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

View solution in original post

0 Kudos
10 Replies
LucD
Leadership
Leadership
Jump to solution

You are aware that the script writes the report to the CSV file C:\export.csv ?


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

0 Kudos
steve31783
Enthusiast
Enthusiast
Jump to solution

Yes.. here is what I see for output in that file:

#TYPE System.Management.Automation.PSCustomObject

VMName,Hostname,OS,IPAddress,VMState,TotalCPU,TotalMemory,MemoryUsage,TotalNics,ToolsStatus,ToolsVersion,MemoryLimit,MemoryReservation

,,,,,,,,,,,,

,,,,,,,,,,,,

,,,,,,,,,,,,

,,,,,,,,,,,,

,,,,,,,,,,,,

I have also tried displaying output on the screen, and pushing it to and htm file (using

" ConvertTo-HTML -head $a | Set-Content C:\test.htm "

No output for any method..

0 Kudos
LucD
Leadership
Leadership
Jump to solution

And the Get-VIServer points to your Virtual Center with a valid account and password ?


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

0 Kudos
steve31783
Enthusiast
Enthusiast
Jump to solution

Sure does.. i've actually tried with 3 different accounts that have VC access.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

And does Get-VM by itself return anything?


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

0 Kudos
steve31783
Enthusiast
Enthusiast
Jump to solution

Yes, it returns each of my VMs, wether its powered on/off, CPU, memory, etc.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Did you try stopping/starting the application (VI Toolkit prompt, PowerShell+...) from where you run the script ?

Does this return anything ?

Get-VM | %{Get-View $_.ID}


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

0 Kudos
steve31783
Enthusiast
Enthusiast
Jump to solution

Weird.. shutting down the vi toolit and restarting fixed the issue. Thanks for the help!

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I get this from time to time as well.

The problem is also mentioned in a few other discussions in this community.


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

0 Kudos
steve31783
Enthusiast
Enthusiast
Jump to solution

Thanks again for the help....

0 Kudos