?
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
?
543 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
Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
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

765 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