PowerCLI

 View Only
Expand all | Collapse all

Find VM with an specific IP Address

  • 1.  Find VM with an specific IP Address

    Posted Feb 21, 2011 11:20 AM

    hi!

    I want to find a VM with a specific IP Address. I try

    $my = get-vm |where {$_.guest.ipaddress -eq "10.33.126.40"}

    This worked..but its extremly slow.

    Is there an faster way?



  • 2.  RE: Find VM with an specific IP Address

    Posted Feb 21, 2011 11:24 AM

    From where you want to find a specific ip? host? vMA? powershell?



  • 3.  RE: Find VM with an specific IP Address

    Posted Feb 21, 2011 11:32 AM

    with powershell (PowerCLI)



  • 4.  RE: Find VM with an specific IP Address

    Posted Feb 21, 2011 12:05 PM

    Try this, it should in theory be the fastest method since the filtering is done on the vCenter

    Get-View -ViewType VirtualMachine -Filter @{"Guest.IpAddress"="10.33.126.40"}
    


  • 5.  RE: Find VM with an specific IP Address

    Posted Feb 21, 2011 12:14 PM

    Hello,

    As I am not script guru, the quickest way to VM via IP is to use the search funtion in Vspere. Simple type the IP in the vsphere client search and the VM is there.

    I hope this helps.



  • 6.  RE: Find VM with an specific IP Address

    Posted Feb 21, 2011 12:16 PM

    I had tried Luc's script before and did not get it working. So I gave my previous example. Now I see that IpAddress in Guest.IpAddress is case sensitive. I wrote Guest.IPAddress in my test script and that gave an error. So be carefull to use the right case. :smileywink:

    The error I got was:

    [vSphere PowerCLI] C:\users\robert> Get-View -ViewType VirtualMachine -Filter @{"Guest.IPAddress"="10.33.126.40"}
    Get-View : 21-2-2011 13:15:33    Get-View
    At line:1 char:9
    + Get-View <<<<  -ViewType VirtualMachine -Filter @{"Guest.IPAddress"="10.33.126.40"}
        + CategoryInfo          : NotSpecified: (:) [Get-View], InvalidProperty
        + FullyQualifiedErrorId : Client20_MoServiceImpl_GetNetInteropEntityView_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInterop.GetVIView



  • 7.  RE: Find VM with an specific IP Address

    Posted Feb 21, 2011 12:52 PM

    Hi Robert,

    I will file a bug for this issue.

    Vitali

    PowerCLI Team



  • 8.  RE: Find VM with an specific IP Address

    Posted Feb 21, 2011 12:55 PM

    I'm not sure this is a PowerCLI bug.

    Afaik, the names in the PropertySpec are also case-sensitive.



  • 9.  RE: Find VM with an specific IP Address

    Posted Feb 21, 2011 12:59 PM

    Hi Luc,

    the strange thing is that in "Guest.IpAdress" IpAddress is case sensitive, but Guest is not. This is at least not consistent.

    Regards, Robert



  • 10.  RE: Find VM with an specific IP Address

    Posted Feb 21, 2011 12:56 PM

    Hi Vitali,

    Thanks.

    Regards, Robert



  • 11.  RE: Find VM with an specific IP Address

    Posted Feb 23, 2012 10:31 AM

    Hello,

    since the -Filter works like a RE, it's probably better to surround the IP address with ^$, so you just find the exact match:

    Get-View -ViewType VirtualMachine -Filter @{"Guest.IpAddress"="^192.168.1.1$"}

    Bye,

    Claudio



  • 12.  RE: Find VM with an specific IP Address

    Posted Feb 21, 2011 11:33 AM

    Can you try the next script and see if it is faster?

    Get-View -ViewType virtualmachine -Property Guest.IPAddress | `
    Where-Object {$_.Guest.IPAddress -eq "10.33.126.40"} | `
    Get-VIObjectByVIView
    
    

    Regards, Robert



  • 13.  RE: Find VM with an specific IP Address

    Posted Feb 21, 2011 11:58 AM

    Did you try Get-VM | select "NAME OF VM", {$_.Guest.IPAddress}

    where NAME OF VM is the name as you see it in the virtual center



  • 14.  RE: Find VM with an specific IP Address

    Posted Feb 21, 2011 12:05 PM

    What I meant was.. if with the command I wrote in the previous post is slow too.