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
542 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 500 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Always backup Domain, SYSVOL etc.using processes according to Microsoft Best Practices. This is meant as a disaster recovery process for small environments that did not implement backup processes and did not run a secondary domain controller that ne…
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
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 …
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.

688 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