Solved

DirectoryEntry how to make a copy of a user account?

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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
GET INFO ABOUT WHAT THE PRINTER IS DOING ? 11 66
search by any word in column 5 25
PowerShell:  foreach where object notmatch? 17 68
CSS styling problem 3 19
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
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…

731 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