[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 64
  • Last Modified:

DirectoryEntry how to make a copy of a user account?

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
lapucca
Asked:
lapucca
  • 3
  • 2
1 Solution
 
Najam UddinCommented:
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
 
lapuccaAuthor Commented:
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
 
Najam UddinCommented:
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
 
lapuccaAuthor Commented:
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
 
lapuccaAuthor Commented:
I just code it such that I copy each property that I want to copy.  Thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now