Solved

DirectoryEntry how to make a copy of a user account?

Posted on 2015-02-10
5
45 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
  • 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now