VMware Cloud Community
tdubb123
Expert
Expert
Jump to solution

$vm.numcpu blank

hi

why am I not getting anything on numcpu or mmeory gb

$

results = @()

$vms = get-content "c:\servers.txt"

foreach ($vm in $vms) {

$vmhardisk = get-vm $vm | get-harddisk

$result = ""| select vmname, numcpu, memorygb, harddiskname, harddiskcapacitygb

$result.vmname = $vm

$result.numcpu = $vm.numcpu

$result.memorygb = $vm.memorygb

$result.harddiskname = $vmharddisk.name

$result.harddisklcapacitygb = [system.math]::round($vmharddisk.capacitygb, 0)

$results += $result

}

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Since you are populating it with Get-Content, it's a string.


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

View solution in original post

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

The $vm holds a string with name of the VM, not the object.

Change the line to

$vms = Get-VM -Name (Get-Content "c:\servers.txt")


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

Reply
0 Kudos
tdubb123
Expert
Expert
Jump to solution

hi luicd,

how can i tell if $vm is a string or object?

Reply
0 Kudos
HORSTJ
Enthusiast
Enthusiast
Jump to solution

Try $vm.GetType().FullName

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Since you are populating it with Get-Content, it's a string.


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

Reply
0 Kudos