Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Is there a script or prog which can says if a sever is belong to a domain in AD?

Posted on 2011-02-14
10
Medium Priority
?
544 Views
Last Modified: 2013-03-09
Is there a script or prog which can says if a sever is belong to a domain in AD?

For exemple, I have a list of servers in a file and would like to know in which domain they are belong in AD.

Thank you.
0
Comment
Question by:SAM2009
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 3

Accepted Solution

by:
chandra_darbha earned 2000 total points
ID: 34894321
Found this code at http://blog.dotsmart.net/2009/03/11/getting-a-machine%E2%80%99s-netbios-domain-name-in-csharp/ and modified it to take machine name as input parameter. Invoke the NetUtil.GetMachineNetBiosDomain("machinename"); from your code.

Hope that helps.

class NetUtil
{
    [DllImport("netapi32.dll", CharSet = CharSet.Auto)]
    static extern int NetWkstaGetInfo(string server,
        int level,
        out IntPtr info);

    [DllImport("netapi32.dll")]
    static extern int NetApiBufferFree(IntPtr pBuf);

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
    class WKSTA_INFO_100
    {
        public int wki100_platform_id;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string wki100_computername;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string wki100_langroup;
        public int wki100_ver_major;
        public int wki100_ver_minor;
    }

    public static string GetMachineNetBiosDomain(string machineName)
    {
        IntPtr pBuffer = IntPtr.Zero;

        WKSTA_INFO_100 info;
        int retval = NetWkstaGetInfo(machineName, 100, out pBuffer);
        if (retval != 0)
            throw new Win32Exception(retval);

        info = (WKSTA_INFO_100)Marshal.PtrToStructure(pBuffer, typeof(WKSTA_INFO_100));
        string domainName = info.wki100_langroup;
        NetApiBufferFree(pBuffer);
        return domainName;
    }
}

Open in new window


Thanks,
Chandra
0
 
LVL 3

Expert Comment

by:chandra_darbha
ID: 34894326
Sorry, haven't noticed that you wanted a VB script. This is a C# implementation. There should be an equivalent implementation in VB.

Thanks,
Chandra
0
 
LVL 12

Expert Comment

by:Amick
ID: 34894387
To determine whether a given computer in a list of computers is an active member of a given domain you can invoke
for /f %i in (serverfile.txt) do net view /domain:mydomain %i

Open in new window

The response is either a list of available shares which verifies membership, or a message that the network path was not found which suggests non-membership or out-of-service.

I realize this isn't exactly the solution you wanted, but it may be useful.
0
Q2 2017 - Latest Malware & Internet Attacks

WatchGuard’s Threat Lab is a group of dedicated threat researchers committed to helping you stay ahead of the bad guys by providing in-depth analysis of the top security threats to your network.  Check out our latest Quarterly Internet Security Report!

 
LVL 39

Expert Comment

by:Krzysztof Pytko
ID: 34894429
Try with PowerShell (Quest cmdlets for 2003 AD)
http://www.quest.com/powershell/activeroles-server.aspx

Create text file with servers on C-Drive (one server name per line) and run in PowerShell

 
Get-Content c:\servers.txt | ForEach-Object {Get-QADComputer $_ | Select name,domain | Export-CSV c:\output.csv}

Open in new window


Regards,
Krzysztof
0
 
LVL 1

Author Comment

by:SAM2009
ID: 34896368
If I have many domains in AD does it works also?
0
 
LVL 39

Expert Comment

by:Krzysztof Pytko
ID: 34896440
yes, but you need to change a little bit search node

 
Get-Content c:\servers.txt | ForEach-Object {Get-QADComputer -SearchRoot "dc=domain,dc=com" $_ | Select name,domain | Export-CSV c:\output_DomainName.csv}

Open in new window


where dc=domain,dc=com is FQDN of your domain and you need to specify output file name

Krzysztof
0
 
LVL 1

Author Comment

by:SAM2009
ID: 34896903
Hhumm it just give me the last server on the list with default domain name. Could you try?
0
 
LVL 39

Expert Comment

by:Krzysztof Pytko
ID: 34897050
Yes, because you need to run this script for each domain separately :) So, text file with server must be from the same domain :)

Krzysztof
0
 
LVL 1

Author Comment

by:SAM2009
ID: 34897140
That what I did ok I will try one more time later and let see.
0
 
LVL 1

Author Closing Comment

by:SAM2009
ID: 34939044
Thank you
0

Featured Post

Q2 2017 - Latest Malware & Internet Attacks

WatchGuard’s Threat Lab is a group of dedicated threat researchers committed to helping you stay ahead of the bad guys by providing in-depth analysis of the top security threats to your network.  Check out our latest Quarterly Internet Security Report!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Uncontrolled local administrators groups within any organization pose a huge security risk. Because these groups are locally managed it becomes difficult to audit and maintain them.
Active Directory can easily get cluttered with unused service, user and computer accounts. In this article, I will show you the way I like to implement ADCleanup..
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question