Link to home
Start Free TrialLog in
Avatar of Member_2_4408773
Member_2_4408773

asked on

C# Virtual machine with Windows Server R2 Active Directory

I've set up a virtual machine using Hyper-V manager. What I want to do is be able to connect to the active directory from the host machine. Can any one tell me how to do this? I need to be able to get a list of users using C#

I can ping the server, but can not access active directory, I've tried adding my laptop to the domain but it can find the domain.
Avatar of Mahesh
Mahesh
Flag of India image

Where is your active directory server?

It is on VM or it is outside hyper-v server?
If its outside hyper-v server,
then U need to create external switch pointing to production adapter on hyper-v server and bind your BM to this virtual network
This will enable VM external access to production network

Then ensure that DC ip is set as DNS server IP on VM tcp/ip and join that machine to domain and then try
change your dns settings and add the ip address of the virtual domain controller to your dns settings. Now you should be able to join the domain
If you're attempting to connect to AD you should be able to do so using the IP of the host:
DirectoryEntry de as new DirectoryEntry("LDAP://1.2.3.4", "username", "password");

Open in new window

If you're already authenticated against the domain you can omit the username and password, but if that were the case you could use serverless binding anyway:
DirectoryEntry de as new DirectoryEntry();

Open in new window

In either case you can pass the authenticated DirectoryEntry to the DirectorySearcher to gather a list of users in the domain.

Chris
Avatar of Member_2_4408773
Member_2_4408773

ASKER

Thanks for your comments.
This is what I have:
Laptop with Windows 8.1 installed. I've installed Hyper-V and created a Windows 2008 R2 Server and installed the following (please see attached Shot1.png).
Shot 2 is what I get when I ping the server.

Shot3 are the settings of the Virtual server. External Virtual Switch selected is the switch I created.

If you need any more information please let me know. I don't really have any experience of configuring servers in this way.

It would be nice to be able to connect to Active Directory using the domain name only.

Thanks in advance
ASKER CERTIFIED SOLUTION
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
screen shot is missing

Still you haven't answered my questions in 1st post
Answers
Where is your active directory server? - On the Virtual Server

It is on VM or it is outside hyper-v server? On the VM

How do I do the following
Add the virtual domain name to your hosts file or change your network adapter dns
Shot1.zip
remove IPv6 checkbox from domain controller virtual machine

Then try to ping DC Ip from Hyper-V host, if require disable DC firewall

If it able to ping, add DC IP on Hyper-V server network card as DNS and then try to ping DC with domain.com

If that works you can join hyper-v server to domain
In VM settings, ensure that VM automatic start action would be always start automatically, this will enable Hyper-V host to logon to domain
http://www.techrepublic.com/blog/data-center/configure-a-hyper-v-vm-for-automatic-startup/
By adding the ip address and the domain this worked. Thanks for all your help
I have accepted a solution as I can now run the code, is it possible to get the host to join the domain? I've tried switching from workgroup to a domain but its says it cant contact it?