Solved

DirectoryEntry how to make a copy of a user account?

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
"Emulate" TAB key when press Enter Key 3 64
Unlocking a column in excel using C# 17 26
Asp.Net Session Question 2 33
How to escape alias names for Oracle query 1 24
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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

680 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