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...
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
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
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..
And the Get-VIServer points to your Virtual Center with a valid account and password ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Sure does.. i've actually tried with 3 different accounts that have VC access.
And does Get-VM by itself return anything?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes, it returns each of my VMs, wether its powered on/off, CPU, memory, etc.
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
Weird.. shutting down the vi toolit and restarting fixed the issue. Thanks for the help!
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
Thanks again for the help....