VMware Cloud Community
TheVMinator
Expert
Expert
Jump to solution

Get VMs in a subnet

I need to get all VMs in a given subnet with something like this:

get-vm | where{$_.2ndOctet -eq "110"}  #(you get the idea)

How can I select a set of VMs based on their IP address so that I get all VMs in the 10.110.0.0 /16 subnet?

Thanks!

0 Kudos
1 Solution

Accepted Solutions
sneddo
Hot Shot
Hot Shot
Jump to solution

The simplest way would be something like this:

Get-View -ViewType VirtualMachine | Where {$_.guest.IpAddress -like "10.110.*.*"} | Select Name, {$_.guest.IpAddress}

If you're comfortable with regular expressions you could do something like this as well:

Get-View -ViewType VirtualMachine | Where {$_.guest.IpAddress -match "10\.110\.[65-66]\.*"} | Select Name, {$_.guest.IpAddress}

View solution in original post

0 Kudos
2 Replies
sneddo
Hot Shot
Hot Shot
Jump to solution

The simplest way would be something like this:

Get-View -ViewType VirtualMachine | Where {$_.guest.IpAddress -like "10.110.*.*"} | Select Name, {$_.guest.IpAddress}

If you're comfortable with regular expressions you could do something like this as well:

Get-View -ViewType VirtualMachine | Where {$_.guest.IpAddress -match "10\.110\.[65-66]\.*"} | Select Name, {$_.guest.IpAddress}

0 Kudos
TheVMinator
Expert
Expert
Jump to solution

great thanks!

0 Kudos