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
541 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
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 
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

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.

Question has a verified solution.

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

Suggested Solutions

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

738 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