Solved

DirectoryEntry how to make a copy of a user account?

Posted on 2015-02-10
5
58 Views
Last Modified: 2015-02-24
Hi, I'm using VS2012.

It turns out the DirectoryEntry.Copy method isn't implemented for LDAP, majority of network out there I think.

I googled trying to find code already written out there for this but didn't find any.  Appreciated it if you know where it is and provide links to it.  

If i were to write my own CopyTo mehtod, please provide guideline.  I can create a user where I want it.  Now, do I loop though all properties of the other user account (except for samaccount, upn and parentid, and what else?0 properties and copy them?  

Thank you.
0
Comment
Question by:lapucca
[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
  • 3
  • 2
5 Comments
 
LVL 10

Expert Comment

by:Najam Uddin
ID: 40603656
Raw code, not executed

Are you looking for some thing like this? I am unable to understand the exact problem you are facing

public static class Extension
{
	public static DirectoryEntry CreateUserAccount(this DirectoryEntry Source, DirectoryEntry Target)
	{
		try
		{
			for(var index = 0; index < Source.Properties.Count; index++)
			{			    
				Target.Properties[index].Value = Source.Properties[index].Value;
			}
		}
		catch (System.DirectoryServices.DirectoryServicesCOMException E)
		{
		   
		}
		return oGUID;
	}
}

Open in new window


in for loop you can skip what all properties you don't want to copy.
0
 

Author Comment

by:lapucca
ID: 40603855
https://msdn.microsoft.com/en-us/library/hz4574y2%28v=vs.110%29.aspx  
Here is the copyTo method I was referring to, sorry forgot to provide the link.  This is not implemented in ldap.

So, I need to create my own method doing the same thing.  I was hoping to find it already done of example but no luck searching for an example.  So, creating a user is simple.  However, I need to use another user account as a template.  I need to make sure new ad user account has the same group membership and permission(Under security tab in ADUC).
Thank you.
0
 
LVL 10

Accepted Solution

by:
Najam Uddin earned 500 total points
ID: 40603914
The code I gave, it takes 2 DirectoryEntry objects and copiex properties of one in another (name of function was wrong in my code)
Are you looking for something else?
0
 

Author Comment

by:lapucca
ID: 40604159
Have you tried that?  Does that code work?  Is that copying all the attributes from one user object to another?
Thank you.  
Do you know how I can set the properties in the Security Tab in User properties in ADUC?  i need to mimic the same security setting as the template user account.  Or is this part of the properties copying?
Thank you.
0
 

Author Closing Comment

by:lapucca
ID: 40628953
I just code it such that I copy each property that I want to copy.  Thanks
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

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