none
How to get virtual machine NetBIOS names? Can I use powershell to list all virtual machines hostnames (including linux?) RRS feed

  • Question

  • How to get virtual machine NetBIOS names? Can I use powershell to list all virtual machines hostnames (including linux?)

    I need a simpls list, a text file, with one hostname/netBIOS name per line, the hostnames/netbios names of all virtual machines (stand-alone or cluster)



    Al VMs running in a Hyper-V Host under my admin control
    • Edited by KayZerSoze Tuesday, July 12, 2016 2:39 PM not enough information
    Tuesday, July 12, 2016 12:15 PM

Answers

  • Good call, of course the method to get all VM hostname/netbios names (if possible) it will use diferente methods/procedures in each case

    As far the topic is going further makes me almost sure that couldn´t be possible to generate a listing of all hostnames/netbios names of all VMs running under a particular Hyper-v

    The solutions, for now, is to use the display name of the VM (GEt-VM solves the problem) MANUALLY configured to be the hostname/Netbios name of the VM, so, the get-vm would do the job. It´s not the better solution, but ...

    I saw a tool that syncs the hostname/netbios name of the VM, changing the display name of the VM on hyper-v, even if you renamed the VM, but it needs a local install of the tool in all VMs.. not so fancy...

    • Marked as answer by KayZerSoze Tuesday, July 12, 2016 7:01 PM
    Tuesday, July 12, 2016 7:01 PM

All replies

  • Wave a magic wand and your text file will magically appear.

    But seriously: Virtual machines appear as computers on the network just like physical hosts. (That's the cool part about virtual machines, after all.)

    You need to ask a clear question. Are you wanting to query Active Directory for computer objects?


    -- Bill Stewart [Bill_Stewart]

    Tuesday, July 12, 2016 2:20 PM
    Moderator
  • Of course i know that there is an "abstraction" between Host and Guest, isolating then, but... it´s not impossible...

    (-:

    AD is not an option, there is a lot of workgroup and Linux machines, mixed physical and VMs on the same network.. the only portion in common is: all VMs running on a particular Host

    So the answer is.. impossible?

    (without SC VMM)
    • Edited by KayZerSoze Tuesday, July 12, 2016 2:38 PM typo
    Tuesday, July 12, 2016 2:36 PM
  • What is impossible? You have not yet asked a clear question.

    -- Bill Stewart [Bill_Stewart]

    Tuesday, July 12, 2016 2:42 PM
    Moderator
  • Start with Get-VM. This will find all VMs on your system/network.

    I recommend that you start by doing some training on virtualization.   You might also want to post basic VM  questions in the Hyper-V forum until you have a basic understanding of Hyper-V.


    \_(ツ)_/

    Tuesday, July 12, 2016 6:16 PM
  • Note that, under normal circumstances, Linux des not have a NetBIOS name.  It may have a network name like an FQDN. 

    \_(ツ)_/

    Tuesday, July 12, 2016 6:17 PM
  • Good call, of course the method to get all VM hostname/netbios names (if possible) it will use diferente methods/procedures in each case

    As far the topic is going further makes me almost sure that couldn´t be possible to generate a listing of all hostnames/netbios names of all VMs running under a particular Hyper-v

    The solutions, for now, is to use the display name of the VM (GEt-VM solves the problem) MANUALLY configured to be the hostname/Netbios name of the VM, so, the get-vm would do the job. It´s not the better solution, but ...

    I saw a tool that syncs the hostname/netbios name of the VM, changing the display name of the VM on hyper-v, even if you renamed the VM, but it needs a local install of the tool in all VMs.. not so fancy...

    • Marked as answer by KayZerSoze Tuesday, July 12, 2016 7:01 PM
    Tuesday, July 12, 2016 7:01 PM
  • Install SNMP on all hosts and use SNMP to query for name by IP.  If you are using DNS then use tracert or GetHostNameByAddress.

    Without DNS finding hosts will be an issue.   When we are building large networks we will always install a DNS and, when possible, use DHCP to acquire a configuration.


    \_(ツ)_/

    Tuesday, July 12, 2016 7:07 PM
  • that will do it for me, for windows only

    using tracert

    powershell

    my tracert is in french, so maybe you need to change the position in the array of the result

    cls
    $vms01 = hyper-v\Get-VM # -Computername $HostName

    #Get-VM -VMName -ErrorAction SilentlyContinue | Select-Object VMName, ComputerName

    #$vms01 | Select-Object VMName, ComputerName

    #$vms01[2]| Select-Object VMName, ComputerName, ip
    $network_adapters01 = $vms01[2].NetworkAdapters

    $foundname01 = 0
    foreach($network_adapter in $network_adapters01)
    {
        foreach($address in $network_adapter.IPAddresses)
        {
            if($address -ne $null)
            {

                $Occurrences = $address.Split(".").GetUpperBound(0)
                if($Occurrences -eq 3)
                {
                    $address
                    # get machine name from ipv4 resolution in tracert
                    $tracert_res = tracert -h 1 -w 1 $address
                    # split line 1 to get name
                    $vm_name_tracert01 = $tracert_res[1].Split(" ")

                    $vm_name_tracert01[$vm_name_tracert01.GetUpperBound(0)-1]
                }
            }
        }
    }

                                

    Wildboy85

    Sunday, February 2, 2020 3:27 AM