it just runs and runs... no error
I think the problem is in the foreach....
thanks!!!
$Report = @()
foreach ($vm in get-vm -Location mycluster )
{
Get-VM $vm |sort-object name | %{
$ReportRow = "" | Select-Object vm, totaldisk, mem, cpu
$ReportRow.vm = $_.Name
$ReportRow.totaldisk = [math]::Round(($_.Guest.Disks | Measure-Object CapacityGB -Sum | Select -ExpandProperty Sum))
$ReportRow.cpu = $vm.extensiondata.summary.config.numcpu
$ReportRow.mem = $vm.Extensiondata.Summary.Config.memorySizeMB
}
$Report += $ReportRow
}
What u want to do ? Get Vm details like cpu etc ?
You can check if the VMs from the cluster are returned correctly.
get-vm -Location mycluster
If they are, try running like this
$Report = @()
foreach ($vm in get-vm -Location mycluster )
{
$ReportRow = "" | Select-Object vm, totaldisk, mem, cpu
$ReportRow.vm = $_.Name
$ReportRow.totaldisk = [math]::Round(($_.Guest.Disks | Measure-Object CapacityGB -Sum | Select -ExpandProperty Sum))
$ReportRow.cpu = $vm.extensiondata.summary.config.numcpu
$ReportRow.mem = $vm.Extensiondata.Summary.Config.memorySizeMB
$Report += $ReportRow
}
$Report
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I tested to make sure it can access the vms as I expected, it can get to all the vms from the cluster. it just run s and runs, never errors.
it started to happen once I added the foreach when I added the cpu and memory.
The original script uses this method
$ReportRow.totaldisk = [math]::Round(($_.Guest.Disks | Measure-Object CapacityGB -Sum | Select -ExpandProperty Sum))
to pull info
..
..
plus 3 more
for the cpu and memory, i only know this method which includes $vm, hence why I added the foreach.
$ReportRow.cpu = $vm.extensiondata.summary.config.numcpu
$ReportRow.mem = $vm.Extensiondata.Summary.Config.memorySizeMB
I could not figure out an easier way to incorporate the two type of info gathering
Does it also run forever if you get that info for a single VM ?
Is there a specific VM where it runs forever ?
Perhaps add some debugging steps into the script to know where it goes wrong ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
no, I was initially running it with 1 vm just to get my code right, it runs and takes 10 secs or so, but it does complete. is it just that it is just a poorly designed script.
debugging, any hints on what to check...please
For debugging I would start with listing the $vm variable in the beginning of the ForEach loop.
That way you should be able to see where (for which VM) the script hangs, or if it is a general problem.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
well,
it does work.. it is not very fast since it basically is serial cause of the foreach, but it works. I'm not sure why it was not working before. maybe I was too impatient. oh well good enough, thanks for the second pair of eyes