mrray
Enthusiast
Enthusiast

Sorting VM IP against a list from a text file

Jump to solution

Happy Friday, PowerCLI community Smiley Happy

I have been tasked with getting a list of VMs that have IP addresses that match the IPs on a list, given to me in a text file.

My thought was then to import the text file as an array, look for VMs where the calculated IP address would match any in the array.

What I did looks like this:

$ipadds = Get-Content .\Documents\ntp_queries.txt

Get-VM | where {$_.@{N="IP Address";E={@($_.guest.IPAddress[0])}} -like $ipadds }

select Name,PowerState, @{N="IP Address";E={@($_.guest.IPAddress[0])}} | Out-GridView

Runs fine, but wit no output, so I assume my filter is not written properly....

any ideas?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

Not sure what you are doing in that Where-clause, but I think the following might do the trick.

$ipadds = Get-Content .\Documents\ntp_queries.txt

Get-VM | where {$ipadds -contains $_.guest.IPAddress[0]} |

select Name,PowerState, @{N="IP Address";E={@($_.guest.IPAddress[0])}} | Out-GridView


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership

Not sure what you are doing in that Where-clause, but I think the following might do the trick.

$ipadds = Get-Content .\Documents\ntp_queries.txt

Get-VM | where {$ipadds -contains $_.guest.IPAddress[0]} |

select Name,PowerState, @{N="IP Address";E={@($_.guest.IPAddress[0])}} | Out-GridView


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

View solution in original post

0 Kudos
mrray
Enthusiast
Enthusiast

I was trying to actually figure it out on my own, not wanting to bother LucD for once Smiley Wink

But fwiw, I kind of get what I did wrong.

Thank you!

0 Kudos