locked
List pc hostname in workgroup RRS feed

  • Question

  • Hi,

    i have to found all pc hostname in a lan, but i haven't a domain controller.

    Is there a powershell command to get the pc hostname list ?

    Thursday, May 18, 2017 2:18 PM

All replies

  • [system.net.dns]::GetHostByAddress('10.0.0.10').HostName

    \_(ツ)_/

    Thursday, May 18, 2017 2:31 PM
  • Good, but if i have an entire class of ip like: 192.168.1.1 to 192.168.1.254

    or a subnet like 10.0.0.1 / 255.255.240.0 how can i scan to search all pc hostname ?

    Thursday, May 18, 2017 2:34 PM
  • You will have to enumerate all addresses and test them.

    \_(ツ)_/

    Thursday, May 18, 2017 2:36 PM
  • How can i do ?

    something like this ?

    $iprange = ( 192.168.1.1 .. 192.168.1.254 )
    
    $i = 0
    
    $hostnames = @()
    
    foreach ($ip in $iprange) {
    
    $hostname = [system.net.dns]::GetHostByAddress('$ip').HostName
    
    $hostnames += $hostname
    
    $i++
    
    }


    Thursday, May 18, 2017 2:43 PM
  • 1..254

    1..254 | %{ "192.168.1.$_"}


    \_(ツ)_/

    Thursday, May 18, 2017 2:55 PM