Automation

 View Only
Expand all | Collapse all

List DHCP server list in the vSphere environment

  • 1.  List DHCP server list in the vSphere environment

    Posted Sep 14, 2023 01:18 PM

    Hello

    I need to retrieve all the DHCP servers that cater to the DHCP-enabled vSphere VMs in the datacenter. How do I do that using PowerShell? I assume this information resides on the VM Hosts?

    I can connect to the vCenter server,  retrieve VMs and the corresponding VMHosts. Just need to collect DHCP inventory.

    Thanks



  • 2.  RE: List DHCP server list in the vSphere environment

    Posted Sep 14, 2023 04:21 PM

    That information does, afaik, not sit on the ESXi nodes.
    You will have to query the Guest OS on the VMs to retrieve that information.
    If your VMs have the VMware Tools installed, you can use the Invoke-VMScript cmdlet to run code/commands inside the Guest OS.
    What code to use depends on the type of the Guest OS.



  • 3.  RE: List DHCP server list in the vSphere environment

    Posted Sep 15, 2023 06:37 AM

    Thank you. I realised after posting my question that DHCP is part of general IT infrastructure so vSphere wouldn't know about it natively (of course the server hosting DHCP could as well be on of the VMs).

    But how would I check using PowerShell if DHCP is enabled on the VM?



  • 4.  RE: List DHCP server list in the vSphere environment

    Posted Sep 15, 2023 08:24 AM

    I repeat from my previous reply "What code to use depends on the type of the Guest OS."



  • 5.  RE: List DHCP server list in the vSphere environment

    Posted Sep 15, 2023 08:29 AM

    oops sorry, we have both Windows servers and a variety of Linux (including the prominent distros) in the estate



  • 6.  RE: List DHCP server list in the vSphere environment

    Posted Sep 15, 2023 10:39 AM

    In a Windows OS you can use the command ipconfig/all to retrieve DHCP information.

    On most Linux distributions you could do something like grep dhcp-server-identifier /var/lib/dhcp/dhclient.leases



  • 7.  RE: List DHCP server list in the vSphere environment

    Posted Sep 15, 2023 11:14 AM

    ah.. I was looking at the vCenter level inventory as opposed to burrowing into each VMs to run ipconfig.

    I thought there was a DHCPEnabled setting available somewhere in the vCenter VM-Network inventory but can't seem to get hold of it.



  • 8.  RE: List DHCP server list in the vSphere environment

    Posted Sep 15, 2023 11:18 AM

    If you have the VMware Tools installed, you can check if the info is available in

    $vm = Get-VM -Name MyVM
    $vm.ExtensionData.Guest.IPStack.DhcpConfig


  • 9.  RE: List DHCP server list in the vSphere environment

    Posted Sep 15, 2023 11:25 AM

    I do not think we have the VMWare tools installed so I need to look into the IPConfig route.

    Thanks for your help as always.



  • 10.  RE: List DHCP server list in the vSphere environment

    Posted Sep 15, 2023 03:03 PM

    If you don't have the VMware Tools installed, you will not be able to use the Invoke-VMScript cmdlet either I'm afraid



  • 11.  RE: List DHCP server list in the vSphere environment

    Posted Sep 22, 2023 10:53 AM

    Thanks. Another team has managed to obtain this info using their infrastructure tooling.



  • 12.  RE: List DHCP server list in the vSphere environment

    Posted Sep 25, 2023 03:17 PM

    LucD,

    I tried the as mentioned. but DhcpConfig shows blank.

    VMware Tools are running on the server.

    ganapa2000_0-1695655024324.png

     

     



  • 13.  RE: List DHCP server list in the vSphere environment

    Posted Sep 25, 2023 05:35 PM

    Did you also check under $vm.ExtensionData.Guest.Net.IpConfig?



  • 14.  RE: List DHCP server list in the vSphere environment

    Posted Sep 26, 2023 06:32 AM

    LucD,

    Below is the requested output

    ganapa2000_1-1695709908353.png

     

     



  • 15.  RE: List DHCP server list in the vSphere environment

    Posted Sep 26, 2023 07:00 AM

    Then it looks as if the VMware Tools were not able to extract that info from the Guest OS.
    The IpStack documentation does mention "Guest information about IP networking stack, if known".

    You will have to query inside the Guest OS with a Guest OS native command (through for example Invoke-VMScript)



  • 16.  RE: List DHCP server list in the vSphere environment

    Posted Sep 26, 2023 03:21 PM

    Sure LucD, Thanks for the update.