All
I have recently started scripting using Powershell and as great a language it is I'm still at the 'very' early learning stages. All I would like to do is create a script that reads some hosts from a text file and then gets some info off all the VMs associated within that host. I know the get-vm command can do that for ALL the VMs within VC but when i run my script it seems to get the info for the entire VC and NOT on a per host basis. (We have many hosts within the estate and require the VM info off only a couple)
Heres my script so far (very basic i know!)
$hostlist = (get-vmhost -Name (get-content c:\hosts.txt) | select Name)
#Get VMs for each host
foreach ($esx in $hostlist) {
$VMs = get-vm
foreach ($vm in $VMs) {
Write-host $vm.Name
Write-host $vm.MemoryMB
Write-host $vm.numcpu
Write-host $vm.Guest
}
}
I know its really basic so far but all i am trying to acheive is to simply get some info about some of the VMs and report it back to the console (I'm sure I can send out the info to a spreadsheet myself so now worries there)
Many thanks for you help in advance