Pages: [1]
Print
Author Topic: list virtual machines per cluster  (Read 3804 times)
esarakaitis
Administrator
Sr. Member
*****
Posts: 256


8223109 sack57@hotmail.com littleking57 rootinfortwayne
View Profile WWW Email
« on: February 05, 2009, 10:18:43 AM »

Code:
$clusters = get-cluster

foreach ($cluster in $clusters)
{
    foreach ($vmhost in ($cluster | get-vmhost))
    {
        $vmhost | get-vm | Select-Object @{Name="Cluster"; Expression={$cluster.name}},`
            Name
    }
}
Logged
ewannema
Administrator
Newbie
*****
Posts: 33


View Profile WWW
« Reply #1 on: April 07, 2009, 12:16:10 AM »

I am not sure if this works as intended.  Usually what I see is when a host is a part of the cluster a Get-VMHost | Get-VM will get everything in the cluster.  This kind of makes sense since a host can no longer be a container object.

Can we skip that step altogether?  I am not at a place where I can test this, but I am thinking:

Code:
foreach ($cluster in Get-Cluster)
{
    $cluster | Get-VM | Select-Object @{Name="Cluster"; Expression={$cluster.name}}, Name
}
Logged
esarakaitis
Administrator
Sr. Member
*****
Posts: 256


8223109 sack57@hotmail.com littleking57 rootinfortwayne
View Profile WWW Email
« Reply #2 on: April 07, 2009, 05:39:04 AM »

Good call EW, looks like it works just fine! (your snippet)
Logged
tim_c
Newbie
*
Posts: 2


View Profile
« Reply #3 on: June 02, 2009, 06:37:37 AM »

I am running this script:

foreach ($cluster in Get-Cluster)
{
    $cluster | Get-VM | Select-Object @{Name="Cluster"; Expression={$cluster.name}}, Name`
}


The first time it ran, it worked perfectly.  Now, running it again, only returns the Cluster name (but the number of times it's returned is equal to the number of VM's)

Any ideas?

Thanks
Logged
esarakaitis
Administrator
Sr. Member
*****
Posts: 256


8223109 sack57@hotmail.com littleking57 rootinfortwayne
View Profile WWW Email
« Reply #4 on: June 02, 2009, 09:26:32 AM »

scroll to the right possibly?  im unable to duplicate
Logged
tim_c
Newbie
*
Posts: 2


View Profile
« Reply #5 on: June 02, 2009, 09:34:00 AM »

Scroll to the right, of course! I feel rather stupid now...
Now to export it ...
Logged
esarakaitis
Administrator
Sr. Member
*****
Posts: 256


8223109 sack57@hotmail.com littleking57 rootinfortwayne
View Profile WWW Email
« Reply #6 on: June 02, 2009, 09:52:23 AM »

Tongue wow... really, i was being a smartass Wink
Logged
bmmikee
Newbie
*
Posts: 11


View Profile Email
« Reply #7 on: February 11, 2010, 08:17:34 AM »

Good call EW, looks like it works just fine! (your snippet)

Is it possible to include the IP address of each VM? 
Logged
bmmikee
Newbie
*
Posts: 11


View Profile Email
« Reply #8 on: February 12, 2010, 12:00:03 PM »

This script does exactly what I need.  My question is, how can I add a column for IP addresses of the guests?  I've asked this a few times in different threads - and it has worked...but not as well as this one does.

And this may be asking a lot, but is it possible to include a VLAN number as well?
Logged
esarakaitis
Administrator
Sr. Member
*****
Posts: 256


8223109 sack57@hotmail.com littleking57 rootinfortwayne
View Profile WWW Email
« Reply #9 on: February 12, 2010, 02:51:58 PM »

do add it to this script you'd just add a view of the vm and select the ip

vlan number is not a property of the vm, its a property of the portgroup
Logged
bmmikee
Newbie
*
Posts: 11


View Profile Email
« Reply #10 on: February 12, 2010, 04:00:22 PM »

do add it to this script you'd just add a view of the vm and select the ip

vlan number is not a property of the vm, its a property of the portgroup

Forgive the ignorance, i'm very new to powershell with no learning materials.  I'm just dissecting scripts.  I'm not sure how to accomplish what you are saying. 
Logged
esarakaitis
Administrator
Sr. Member
*****
Posts: 256


8223109 sack57@hotmail.com littleking57 rootinfortwayne
View Profile WWW Email
« Reply #11 on: February 13, 2010, 08:09:47 PM »

look at the other script you asked about, I added the line for you.
Logged
Pages: [1]
Print
Jump to: