Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am looking for a fairly straight forward way of retrieiving a list of machine names in a given NT domain. I have looked through Win32::MiscAdmin and a few other modules and couldn't find what I was looking for. I did however find it in Win32::DomainAdmin but this module is unsupported and seems outdated to some of the other modules.

Does anyone now of an easy method for retrieiving this information, using standardized win32 modules?

  • Comment on Retriving a list of machine names on a NT domain

Replies are listed 'Best First'.
Re: Retriving a list of machine names on a NT domain
by davemabe (Monk) on Mar 28, 2001 at 21:08 UTC
    try

    use Win32::NetAdmin; my @users; Win32::NetAdmin::GetUsers("\\\\PDC",'',\@users); my @computers = grep { /\$$/ } @users; print join("\n",@computers);

      And you can use

      my $dc; Win32::NetAdmin::GetAnyDomainController('','',$dc);
      to get the name of a domain controller for use above. Or, putting it all together:
      #!/usr/bin/perl -w use strict; use Win32::NetAdmin qw( FILTER_SERVER_TRUST_ACCOUNT FILTER_WORKSTATION_TRUST_ACCOUNT ); my( $dc, @comps ); my $domain= @ARGV ? $ARGV[0] : ""; Win32::NetAdmin::GetAnyDomainController('',$domain,$dc) or die "Can't find my domain controller: $^E\n"; Win32::NetAdmin::GetUsers( $dc, FILTER_SERVER_TRUST_ACCOUNT|FILTER_WORKSTATION_TRUST_ACCOUNT, \@comps ) or die "Can't lookup domain members: $^E\n"; s/\$$// for @comps;

      Note that Microsoft changed the definition of "server" and "workstation" early on in the game and in the above code "SERVER" really means "domain controller" and "workstation" really means "domain member computer that isn't a domain controller". So you can request those two lists separately if you like.

              - tye (but my friends call me "Tye")
Re: Retriving a list of machine names on a NT domain
by the_slycer (Chaplain) on Mar 28, 2001 at 21:12 UTC
    With AdminMisc try..
    Win32::AdminMisc::GetMachines($PDC, UF_WORKSTATION_TRUST_ACCOUNT, \@List, "")
    This should return a list of all Workstations on the domain (from the PDC).